To create Executable jar
To create Executable jar files in java
I got 3 ways to  create executable jar files 
we can use 
1. Eclipse
2. Ant script
2. Ant script
3. Java command 
Eclipse method
I created the simple java hello world program to demonstrate this method.
package com.test.createjar;
public class Main {
public static void main(String[] args){
System.out.println("Hello World !");
}
}
To right click the project name and goto Export -> export
1. We get export window
Then we will select Runnable jar file option. It will forward  to the Runnable jar file specification window
2. Runnable jar file specification window
* Here we select the launch configuration as method name and project name
* Destination path and jar file name
After clicks Finish button it created a executable jar file.
2. Ant script
Through ant script also easily to create jar file 
To install ant in ubuntu 12.04 v
 sudo apt-get install ant1.6
  
In eclipse method in Runnable jar file specification window one option like save as a ant script we can choose that option here to create an ant script.
To specify ant file name in output path ex. build.xml
sample :- 
After that ant script is generated automatically in output path.
To run ant script
ant -f build.xml
 
note : if you are using ant 1.7 version or above to run ant script like this ant -buildfile file.xml
 
sample:-
After run this script java program converted as jar file in output file path.
Java command
To create executable jar though command prompt
Step 1 : Need to create manifest file let say manifest.txt. 
   manifest file contains project main class name
Insert main class name in manifest file like this
Main-Class: com.test.mainapp
Insert main class name in manifest file like this
Main-Class: com.test.mainapp
Step 2 :  To create jar file 
Use this command
You can issue following command to create a Helloworld.jar.
jar -cvfm Helloworld.jar manifest.txt com/test/*.class
Use this command
You can issue following command to create a Helloworld.jar.
jar -cvfm Helloworld.jar manifest.txt com/test/*.class
To run java jar file using command prompt
In command prompt type this command
java -jar Executable.jar
Sample output: -





Comments
Post a Comment