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