Sunday, October 26, 2008

Create an executable jar

In order to create an executable jar, you must go to the folder that contains the packages you want to add to the jar. Assumming the folder is bin and the packages are under com (for instance com.company.package*) and the main class is com.packageXX.AppYY(there must be a main class, the class whose main method will be executed when executing the jar), go inside the bin folder. You must create a manifest text file with information related to the application (refer to http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html). Let's assume the manifest file is called "manifest_file". A really simple manifest file should include the following directives:

Main-Class: com.packageXX.AppYY
Created-By: WhoeverCreatedTheApp@wherever

Finally, to create the jar, you just need to execute the jar utility (that comes with the Java SDK) like this:

jar -cmvf manifest_file appyy.jar com

where appyy.jar is the output file.

To execute the jar you can double click it or execute it with :

java -jar appyy.jar

1 Comments:

Blogger Lowfill Tarmak said...

Another easy way of doing that is use the ant jar task ;)

9:53 PM  

Post a Comment

<< Home