Monday, March 7, 2011

Create Executable JAR File Using Eclipse

We all are aware of the main part of an Executable JAR file is keeping the MANIFEST.MF in META-INF Folder. Also inside the MANIFEST.MF we need to provide the following Details.

Manifest-Version: 1.0
  Main-Class: com.example.Example
  Class-Path: dependent.jar
Classpath will be required in case you have more dependent jars are there, also we create the Same jar using the JAR Command provided by Java as follows.
jar cvfm myFile.jar myManifestFile *.class
I found that some of the executable jars will through ClassNotFound Exception.
Hence i recommend to follow the Eclipse Jar Export Option.

The test Project i am going through have a Sample Java file to open a Window using the Java Swing.
Once I execute the project the Output is as Follows.
Now lets Create the JAR to run the Application.
Step 1: Right Click on the Project and Select Export.
Step 2: Select teh Export Destination as Runnable JAR File, and click Next.
Step 3: Select the Class with main method, which need to be executed initially and teh Destination Folder where the Jar need to be saved. Here i selected "C:\test.jar"
Step 4: Click Finish, Now your Executable Jar is ready @ C:\test.jar.
Hope you enjoyed the work through.

3 comments:

Anonymous said...

gud one.. :)

Randy said...

the runnable jar does not include or generate mainfest file. How do you export runnable jar with a manifest file?

RAJA K said...

hELLO THANKYOU