How to create an executable jar with dependency jars

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

Tags:

Java