Creating windows executable launcher of our Java web application

In this tutorial we will see how to create exe launcher for Java web application. For simplicity let us divide this tutorial in several parts. In the first part we will create simple jar launcher which can deploy our web application in embedded server. After successfully achieving this we will see how can we create exe file from it using Java Native interface (JNI).

1. Create launcher jar file using embedded Glassfish api which will remove dependency of server on machine
2. Create exe using JNI invocation API
Part 1:
Lets start with embedding webserver/servlet container in our Java program. Glassfish and Tomcat both provide an api for embedding server in java application. We will be using Glassfish for achieving our purpose.
Requirements:
Here is a test program for launching simple web application:
package test.glassfish;
import org.glassfish.api.deployment.DeployCommandParameters;
import org.glassfish.api.embedded.*;

import java.io.*;
public class WebApplication {
public static void main(String[] args) throws IOException, LifecycleException {
Server.Builder builder = new Server.Builder(“test”);
Server server = builder.build();
server.createPort(8080);
ContainerBuilder containerBuilder = server.createConfig(ContainerBuilder.Type.web);
server.addContainer(containerBuilder);
server.start();
File war = new File(“C:\\Users\\sunils\\maventests\\simple-webapp\\target\\simple-webapp.war“);
EmbeddedDeployer deployer = server.getDeployer();
DeployCommandParameters params = new DeployCommandParameters();
params.contextroot = “simple”;
deployer.deploy(war, params);
}
}
You just need to change path to war file. You should have your web application started under domain http://localhost:8080/simple

As this is embedded server and we want to create exe out of it we need a way to get logging out of it. In next part we will see how to exe launcher from above program

Checked vs Unchecked exception

Checked Exception Unchecked Exception
Forces clients to handle it Clients may not handle it
All exceptions except RuntimeException , Error and their subclasses come under checked exception All RuntimeException , Error and their subclasses come under unchecked exception

Difference between C++ references and Java references

Many people who learn Java with a background of C++ often get confused between reference of C++ and reference of Java. Even if they share same phrase there is not much similarity between them. You might wonder that C++ pointers share the similar functionality that of Java references.

Here is the similarity between C++ pointers and Java references.

C++ Pointers Java references
Declaration and assignment:
Obj* o1;//Uptil now no memory is allocated on heap
o1=new Obj();//Now we have o1 pointing to object on heap
Declaration and assignment:Obj o1;//Uptil now no memory is allocated
o1=new Obj();//Now we have o1 pointing to object on heap
Base class pointer can point to derived class object Base claas reference pointes to derived class object
Obj* o1,o2; o1=new Obj();
o2=o1;
o1 and o2 now point to same object
Obj o1,o2; o1=new Obj();
o2=o1;
o1 and o2 now point to same object



In C++ if we try to assign derived class object to base class reference, object slicing will occur.
From this you can get a idea about how much strong the references are, they allow runtime polymorphism without dealing with pointers. In case of pointers you need to free the memory allocated for pointers. In Java we do not need to wory about freeing allocated memory because system(JVM) takes care of it. So Java tried to achive best of both the worlds. This all comes at the price. As garbage collection ( name of background thread responsible for releasing allocated memory ) run as a background process it slows down the system.

Creating your first website

Just follow following steps and get full fledged website running for you

  • Get an account with web host (you can use http://110mb.com)
  • Domain name(optional if webhost provides it or you can get friendly name at http://co.cc )
  • Website written in PHP (Or you can use CMS i.e. Content management system) Many CMS’s provided by 110mb. you have to just click on ‘one click application installer’ and select appropriate CMS (Before installing CMS delete index.html file through file manager through 110mb controle panel)
  • If you want to have email addresses with your domain you can open google apps account at http://www.google.com/a/cpanel/domain/new
  • If your website/CMS requires a database you can get free database here http://db4free.net (It may take one or two days to activate)
After completing all the above steps I assume:
  • You have an account with web host provider
  • You have domain name with co.cc
  • If you are using CMS ,CMS files uploaded to your root of website.
  • If your website/CMS requires database you have database account with you.
  • If you want friendly domain name you have co.cc domain name. And if you want emails with your websites you have google apps account.

Now let us start setting things up.
  • Log into your google apps account you will get instructions to select verification method, select ‘Change .co.cc CNAME recordoption, press continue
  • Copy the unique string provided to you.
  • Open another tab and navigate to co.cc website, login to your account, select manage your domain name, press set up. Click on “url forwarding” , Select check box “Google apps email setup”, Paste this string to text box. Enter the title. press “Set Up”.
  • Switch back to your google apps tab press “I have completed steps above”
  • You will be prompted to follow guid, Go through the guid if you want to. It will open in different tab. When you complete exploring switch back to prev google apps tab.
  • Press activate email under Email link
  • You will get list of instructions for changing mail extensions. Don’t worry no need to follow those as co.cc has already done that for us. just press “I have completed these steps”
You have just set up an email account for your custom domain. It will take around one or two days to activate depending on your location.
Now let us come back to your website at 110mb.com
You will have a domain name with your website like [xxxxxx].110mb.com. Now you have to configure your domain name with 110mb.
  • Log into your 110mb account
  • Click on- Account management and Upgrade section – Account profile
  • Under Add new domain enter your domain name [ DO NOT PREFIX WITH www] i.e. do not enter http://www..co.cc just enter .co.cc
  • Press “Add or remove My domain now”
  • Go to http://www.110mb.com/check_your_site.php enter your 110mb domain i.e. .110mb.com
  • Copy the ip address.
  • Go to your co.cc domain manager settings as explained previously. Press set up.
  • Press zonal records, there you will have all the configuration for your domain
  • Delete the record having

    <yourname>.co.cc 1 H A


  • Under add arecord click on textbox next to host.(Do not enter anything)
  • Select Type as “A”
  • Paste the ip address you had copied from 110mb domain doctor website
  • Press Set up
Thats it. you have now configured your domain name to point to 110mb domain. This may take two days two take efect.
Now considering that your database is active.
Navigate to your address .110mb.com
You will be prompted to enter information depending on your CMS. Enter database username, password, database name given to you by db4free.net. Enter Server name as db4free.net:3307
And just follow the steps.

I hope this information was useful




CODD’s Rules

Edgar F. Codd is a father of RDBMS ( Relational database management system )

He has putforth twelve rules which DBMS must follow ( 10 followed by Oracle 2 partialy followed )
These rules are
  • Information rule
  • Gauranted access
  • Systematic treatement to NULL
  • Active online catalog
  • Comprehensive data language
  • View updating rule
  • High level Insert,Update,Delete
  • Physical data independence
  • Logical data indepence
  • Distributed independence
  • Integrity indepence
  • No subversion rule

Information rule: It states that all information shold be stored in tables. Information about the tables should also be stored in tables.

Guaranted Access: It states that if you know table name and primary key you should be able to recover unique record.
Systematic treatement to NULL: It states that NULL is not confined to any datatype but it can be stored in all datatypes.
Active Online Catalog: It states that all information about databases should be stored in data dictionary which should be maintained by DBMS.
Comprehensive data language: This rule states that all data should be accessible by language. All DBMS follows this by providing SQL.
View updating rule: All views should be able to do DML operations. (Not followed by all DMBS not even Oracle).
High level Insert,Update,Delete: High level insert update delete should be possible i.e. it should affect multiple records with single query
Physical data independence: This rule states that where data is stored should be taken care by Operating System. This rule is partially followed by Oracle. Oracle tells OS where to store data using hash.
Logical data indepence: This rule states that data can be present anywhere physically but it should be accessible using same query. e.g. when we run select query we get desired result every time even when DBMS keeps on modifying location where data is stored for efficiency purposes.
Integrity independence:
  1. Entety integrity – Concept of primary key
  2. Referncial integrity – Concept of foreign key
  3. Domail integrity – Concept of data type
Distributed independence: DBMS should support distributed database. Followed by oracle.
Non-subversion rule: If relational system has low level language this language should not bypass integrity constraints

Welcome to this blog

I have stated this blog to share whatever i learned building website http://dskvishwa.co.cc/

I have made an attempt to build fully ajax website using

  • RSH0.6 you can read more here
  • XML you can read more here
  • PHP you can read more here
  • MYSQL you can read more here
  • FCK EDITOR you can read more here

If you try navigating this website you will find that for each request entire page will not be loaded instead only dynamic part is loaded, this is achived with the help of xml responce

My Xml Responce contains n nodes

Its DTD is as follows

<!ELEMENT node (eval
(location,( data error ))) >

<!ELEMENT location
(#PCDATA)
>

<!ELEMENT error (#PCDATA)
>

Each node is responsible one of three things

  • Changing innerHTML of one of the elements
  • Raises error using javascript alert
  • Evaluating javascript statements

Example of first type is

<![CDATA[
some formated data
]]>

id_of_some_element_in_html

This node will be responsible for changing innerHTML of element having id id_of_some_element_in_html.

Example of second type is

<![CDATA[

some
error occured on server
side

]]>

some_id_of_element_where_error_message_to_be_printed

This node will be responsible for producing alert statement using javascript

And finally example of third type is

<![CDATA[
some
evaluation
javascript statement
]]>

This node is responsible for evaluating statement on client side

After receiving this responce via ajax you can hand it over to javascript function which will do the parsing

The javascript function i have written is

the one that i have written is

function parseXMLResponce(text){

var

temp=text;

/*

Chopping the advertisement code emited by some free hosts

*/

text=text.substring(text.indexOf(“”),text.lastIndexOf”)+14);


/*Obtaining DomDocument depending on browser*/

var xmlDoc;

var browser=navigator.appName;

if(browser!=’Netscape’) {

xmlDoc=new

ActiveXObject(“Microsoft.XMLDOM”);

xmlDoc.async=”false”;

xmlDoc.loadXML(text);

} else {

try //Firefox, Mozilla,
Opera,etc.

{

parser=new

DOMParser();

xmlDoc=parser.parseFromString(text,”text/xml”);

}

catch(e)

{

alert(e.message);

return;

}

}

var nodeArray;

try

{

//Taking all nodes
in array

nodeArray=xmlDoc.documentElement.childNodes;

}

catch(e){

/*

logging javascript error on server using ajax
request

this will let us know how website is performing

you can
also send browser information in function “logJavascriptError”

temp
contains responce received e.message is general way to get error
message

*/

logJavascriptError(temp,e.message);

alert(‘parse error, please try again’);

return;

}

//collecting the first node

var node=nodeArray[0];

var
loop=nodeArray.length;

for(var
i=0;i<loop;i++){<LOOP;I++)

if(node.nodeName==”node”)

{

var info=node.childNodes;

var info_no=info.length;

var location=””;

var data=””;

var error=””;

var
html_elements=””;

var statement=”;

for(j=0;j<info_no;j++){<INFO_NO;J++)

if(info[j].nodeName==”location”)
{

location=info[j].firstChild.nodeValue;

}

if(info[j].nodeName==”data”) {

data=info[j].firstChild.nodeValue;

}

if(info[j].nodeName==”error” &&

info[j].hasChildNodes()==true) {

error=info[j].firstChild.nodeValue;

}

if(info[j].nodeName==”eval” &&

info[j].hasChildNodes()==true) {

statement=info[j].firstChild.nodeValue;

}

}

if(error==””)

{

//printing the node value in
location

if(location!=”)

{

document.getElementByI(location).innerHTML=data;

}

}

else if(error!=”)

{

//alerting and displaying error in
location

alert(error);

if(document.getElementById(location))

{

document.getElementById(location).innerHTML=error;

}

}

else if(statement!=””)

{

//evaluating
javascript statement

try

{

eval(statement);

}

catch(e)

{

alert(e.message);

}

}

}

//moving on to next sibling

node=node.nextSibling;

}

}

Follow

Get every new post delivered to your Inbox.