Wednesday, May 07, 2008

Make your JAVA application as executable jar file.

1. get the class file for the source code. create package structure for the class file.
In our example i have created a java file with a package structure as com.oracle.samples.HELLOWORLD.java.
Source Code for HELLOWORLD.java file.

package com.oracle.samples;

public class HELLOWORLD
{
public HELLOWORLD()
{
System.out.println("Iam printing from the HELLOWORLD constructor");
}

public static void main(String[] args) {
HELLOWORLD h = new HELLOWORLD();
}

}


D:\jdevstudio10133\jdk\bin\jar cvf HELLOWORLD.jar com\oracle\samples\HELLOWORLD.class

2. Create an empty folder and name it as META-INF.

3. Create a txt file and open that file in an editor. add the following line to it. Once added that line then hit the enter to get an empty line.
The empty line is very important, otherwise your manifest addition will not work.

main-class: com.oracle.samples.HELLOWORLD

D:\jdevstudio10133\jdk\bin\jar umf manifest.txt HELLOWORLD.jar

4. Once you done with the above steps you are ready to run the executable jar file.

D:\jdevstudio10133\jdk\bin\java -jar HELLOWORLD.jar

Note: If you want to add some jar files for your application you need to follow the steps below.
Create a folder called "lib" drop the your jar files under the folder example: log4j-1.2.13.jar or ojdbc14.jar
In the manifest.txt file you have to add one more line to it, add the below line.
Class-Path: lib\ojdbc14.jar lib\log4j-1.2.13.jar
After entering the above in the manifest.txt file you have hit the enter to have a empty line. This is very important otherwise you will get exception.

If you want to add properties file, you have to follow the below steps.
You can add the properties file inside the jar file or you can keep outside the jar file.

No comments:

Post a Comment