I have created a java application which depends upon some external jars. Now I want to create an executable jar for my project. Which means if I double click the project then it should execute.
6 Answers
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

- 103,016
- 27
- 158
- 194
-
The attribute order seems to matter. The Class-Path needs to appear prior to the Main-Class. – dacracot May 03 '10 at 16:57
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

- 51
- 1
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):
- Main-Class: [the fully qualified name of the class in your app that has a main method]
- Class-Path: [the list of JAR dependencies for your application]
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.

- 2,601
- 3
- 22
- 26
You want to set the Class-Path attribute in your JAR's Manifest file.
This page should give you a good starting point.

- 6,109
- 2
- 22
- 18

- 83,208
- 23
- 172
- 177
-
Just to save other time, IzPack is a deployment tool that installs the main jar and the other jars somewhere on a computer, while JSmooth takes all those jars and encapsulates them in with an EXE file so the application can run on Windows. – Lee Meador Jul 17 '18 at 15:29
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.

- 1,481
- 12
- 29