Hi I have created a java application which depends upon some external jars. Now I want to create an executable jar for my project. Means if i double click the project then it should execute.
Thanks Sunil Kumar Sahoo
Hi I have created a java application which depends upon some external jars. Now I want to create an executable jar for my project. Means if i double click the project then it should execute.
Thanks Sunil Kumar Sahoo
You will need to add a MANIFEST.MF file to the JAR for your application, (under the META-INF directory - if you use the 'jar' command line tool it will make sure the file ends up in the right place). It will need to contain two attributes (at least):
More details on manifest files in JAR files can be found here: http://java.sun.com/docs/books/tutorial/deployment/jar/manifestindex.html
If you're using a build tool like Apache Maven you might find that it is able to generate this for you.
If you use Maven the assembly plugin will do this for you very simply: http://maven.apache.org/plugins/maven-assembly-plugin/howto.html
Otherwise you'll need to follow the instructions in the JAR file tutorial: http://java.sun.com/docs/books/tutorial/deployment/jar/index.html and creating a manifest file including your main class as Main-Class: [classname] and listing your external jars as Class-Path: theirJar1 theirJar2 etc.
You want to set the Class-Path attribute in your JAR's Manifest file.
This page should give you a good starting point.
You can do that easily with Ant:
<jar jarfile="MyJar.jar" basedir="bin">
<manifest>
<attribute name="Class-Path" value="lib/lib1.jar lib/lib2.jar lib/lib3.jar"/>
<attribute name="Built-By" value="me"/>
<attribute name="Main-Class" value="mypackage.Myclass"/>
</manifest>
</jar>
This will add all the appropriate entries to the Manifest file. In order to be able to run the jar, you also need to create a lib folder and place all the dependency jars there:
myjar.jar
lib/lib1.jar
lib/lib2.jar
lib/lib3.jar
Use eclipse plugin called "fatjar"
it's update-site
http://kurucz-grafika.de/fatjar
Just right-click on project and use fatjar option, next step allow you to choose which library will be included in *.jar