Generating Single Executable jar file with all dependencies and libraries using Netbeans and Eclipse

Generating Single Jar file 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 file. Click Next.
  3. In the JAR File Specification page, select the resources that you want to export in the Select the resources to export field.
  4. Select the appropriate checkbox to specify whether you want to Export generated class files and resources or Export Java source files and resources. (Note: Selected resources are exported in both cases.
  5. If there are other files 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 file or resource is checked in the window on the right.
  6. In the Select the export destination field, either type or click Browse to select a location for the JAR file.
  7. Select or clear the Overwrite existing files without warning checkbox. If you clear this checkbox, then you will be prompted to confirm the replacement of each file that will be overwritten.
  8. Click Finish to create the JAR file immediately.
  9. Now, navigate to the location you specified 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 file in NetBeans with all dependency and libraries :

Generating single jar file in eclipse is easy but in NetBeans, libraries and dependencies are not automatically combined in one jar file. However there is one time setup required and generating jar file in NetBeans becomes easier than even Eclipse.

Open “build.xml” file generated by NetBeans project and add below “<target>” tag just before   “</project>” tag.

<target name="-post-jar">
    <property name="" value="AllInOneJar"/>
    <property name="store.dir" value="dist"/>
    <property name="store.jar" value="${store.dir}/${}.jar"/>
    <echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
    <jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
        <zipgroupfileset dir="dist" includes="*.jar"/>
        <zipgroupfileset dir="dist/lib" includes="*.jar"/>
            <attribute name="Main-Class" value="${main.class}"/>
    <zip destfile="${store.jar}">
        <zipfileset src="${store.dir}/temp_final.jar"
        excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
    <delete file="${store.dir}/temp_final.jar"/>


  1. your code saved my day.. I am able to create a single application jar file with all the library jars in it. Thanks and credits to you.

  2. I’m using NetBeans 8.0.2 and it is showing following error after adding target tag just before project tag. tips needed.

    Error : Unexpected element “{}target” {}target

  3. 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?

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.