How can I include external jar on my Netbeans project

I solved this by creating just one jar file with all libraries inside, adding the following to my build.xml file in NetBeans:

<target name="-post-jar">
  <jar jarfile="dist/Combined-dist.jar">
    <zipfileset src="https://stackoverflow.com/questions/10834589/${dist.jar}" excludes="META-INF/*" />
    <zipfileset src="lib/commons-io-1.4.jar" excludes="META-INF/*" />
    <zipfileset src="lib/ninja-utils-3.2.jar" excludes="META-INF/*" />
    <zipfileset src="lib/unicorn-1.0.jar" excludes="META-INF/*" />
    <manifest>
        <attribute name="Main-Class" value="com.example.mypackage.Main"/>
    </manifest>
  </jar>
</target>

This creates a jar file (Combined-dist.jar) which is the combination of the dist jar and the specified library jars (in this case, commons-io-1.4.jar,ninja-utils-3.2.jar and unicorn-1.0.jar). You have to be sure to specify your Main Class package for the new jar file or it won’t run when you try to open it.

Leave a Comment