One Jar PDF
One Jar PDF
One Jar PDF
posted by Jitendra on January 19, 2015 under category JAVA and tagged as
Eclipse, jar le, NetBeans with 7 Comments
Generating Single Jar le with all dependencies in Eclipse is easy. We just need to
follow below steps :
1. Either from the context menu or from the menu bar’s File menu, select Export.
2. Expand the Java node and select JAR le. Click Next.
3. In the JAR File Speci cation page, select the resources that you want to export in
the Select the resources to export eld.
4. Select the appropriate checkbox to specify whether you want to Export generated
class les and resources or Export Java source les and resources. (Note: Selected
resources are exported in both cases.
5. If there are other les or resources you want to include they must be in a an open
project. Browse to their location via the directory tree on the left and ensure the
le or resource is checked in the window on the right.
6. In the Select the export destination eld, either type or click Browse to select a
location for the JAR le.
7. Select or clear the Overwrite existing les without warning checkbox. If you clear
this checkbox, then you will be prompted to con rm the replacement of each le
that will be overwritten.
8. Click Finish to create the JAR le immediately.
9. Now, navigate to the location you speci ed for the jar. The icon you see and the
behavior you get if you double click it will vary depending on how your computer
is set up.
10. You can use this article for images and more detail.
How to generate single jar le in NetBeans with all dependency and libraries :
Open “build.xml” le generated by NetBeans project and add below “<target>” tag
just before “</project>” tag.
1 <target name="-post-jar">
2 <property name="store.jar.name" value="AllInOneJar"/>
3 <property name="store.dir" value="dist"/>
4 <property name="store.jar"
value="${store.dir}/${store.jar.name}.jar"/>
5 <echo message="Packaging ${application.title} into a single JAR at
${store.jar}"/>
6 <jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
7 <zipgroupfileset dir="dist" includes="*.jar"/>
8 <zipgroupfileset dir="dist/lib" includes="*.jar"/>
9 <manifest>
10 <attribute name="Main-Class" value="${main.class}"/>
11 </manifest>
12 </jar>
13 <zip destfile="${store.jar}">
14 <zipfileset src="${store.dir}/temp_final.jar"
15 excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
16 </zip>
17 <delete file="${store.dir}/temp_final.jar"/>
18 </target>
Related posts
Bikram Barthakur
September 6, 2016 at 3:18 pm
your code saved my day.. I am able to create a single application jar le with all
the library jars in it. Thanks and credits to you.
Jitendra Zaa
September 6, 2016 at 3:27 pm
Jayanta Pramanik
September 24, 2016 at 3:27 am
I’m using NetBeans 8.0.2 and it is showing following error after adding target tag
just before project tag. tips needed.
Robert N Lockwood
August 6, 2018 at 2:24 pm
Netbeans 8.2
Get an error about duplicate name name=”-post-jar”
argos
May 12, 2018 at 10:12 pm
super Gracias
Kit S Kennedy
October 1, 2018 at 12:26 pm
I need help. I tried your solution and it seemed to work, but when I run it I get
ClassNotFoundException for a required class. I looked in the AllInOneJar.jar and it
is not there, but it is in one of the libraries that is added to the project. Any ideas?
fabiortsf
July 30, 2019 at 12:48 pm
This site uses Akismet to reduce spam. Learn how your comment data is processed.