Tuesday, November 8, 2011

Creating a runnable jar file

Creating a runnable jar requires creating a manifest file. Package the classes files into a jar file. Inside the jar create folder META-INF and create file MANIFEST.MF.
The structure is abc.jar/META-INF/MANIFEST.MF
Edit the manifest file by adding the file to run and library jars required for the program as below example.
Main-Class is the class file to run. Make sure it has public static void main(String[] args) in the class to enable it to run.
Class-Path are the library jars.

Manifest-Version: 1.0
Created-By: 1.6.0_07 (Sun Microsystems Inc.)
Main-Class: my.program.gen.GeneratorProcess
Class-Path: lib/antlr-2.7.6.jar lib/cglib-2.2.jar lib/poi-3.7-20101029.jar lib/poi-examples-3.7-20101029.jar lib/poi-ooxml-3.7-20101029.jar lib/poi-ooxml-schemas-3.7-20101029.jar lib/poi-scratchpad-3.7-20101029.jar lib/xml-apis.jar lib/xmlbeans-2.3.0.jar lib/commons-logging.jar lib/xercesImpl.jar lib/iri.jar lib/jaws-bin.jar lib/icu4j_3_4.jar lib/concurrent.jar lib/dom4j-1.6.1.jar



To run the jar an executable .bat file is useful. A sample content of .bat file are as below

java -Xms512M -Xmx1024M -jar Generator.jar

No comments:

Post a Comment