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.
Use the maven-shade-plugin to package all dependencies into one über-JAR file. It can also be used to build an executable JAR file by specifying the main class.
FYI: In simple terms, the difference between a JAR file and a Runnable JAR is that while a JAR file is a Java application which requires a command line to run, a runnable JAR file can be directly executed by double clicking it.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With