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.
Try this - in the Netbeans IDE:
If you copy your jars into the source code directory, they will be in your final jar. Nevetheless, I am not sure if this will work 100% of the time.
There is a great post at java-forum that states the following:
Except for a select few circumstances, what works best for me is to simply merge the files manually. A .jar is basically a .zip with organized contents, and you can open them in almost any .zip capable archive program (I just use gnome's standard archiver, File Roller, and it works great). Backup your jar file and open it in the archiver of your choice, and do the same for each library jar in the library directory. Drag and drop the working folders (IE, everything EXCEPT the META-INF Directory) from each library into your jar's root path (alongside your META-INF and your app's root package). Now drag the META-INF/MANIFEST.MF file from your jar to your Desktop or any other folder. Open it, and erase the Class-Path and X-COMMENT lines. Don't forget to leave a blank newline at the end of the file! Save the new manifest file and drag it back to your jar's META-INF directory, overwriting the old one. Test the jar.
Follow these:- 1. Right click on project opened in netbeans editor 2. select properties 3. choose libraries 4. add jar 5. click ok
This is what worked for me:
I built in excel export functionality into my project. The 2 external .jars I used for this purpose was jxl.jar end sx.jar
Unpack these 2 jars into a folder(java classes) using 7-Zip without any META files. Unpack your project jar into the same folder including the META file.
Re-Pack the whole java classes folder using JARMaker to recreate your Project .jar in its original distribution folder ... and there you go ... full excel functionality.
Copy that jar file to:
C:\Program Files\Java\jdk\jre\lib\ext
and
C:\Program Files\Java\jre\lib\ext
You should be able to use it in Netbeans and in your manual imports, just like standard imports.
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.