Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I include external jar on my Netbeans project

Tags:

When I run "clean and build" the .jar file that is being created only runs if the lib folder is at the same folder of the .jar file.

So if I move the jar file to the desktop and leave the lib folder in the dist folder, the jar file will give me an exception.

How can I deal with this problem?

like image 841
ksm001 Avatar asked May 31 '12 13:05

ksm001


1 Answers

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="${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.

like image 81
Hemerson Varela Avatar answered Oct 16 '22 18:10

Hemerson Varela