I wanted to package the DLL (dynamic link library) I was using via JNI together with my Java application overall instead of referring to it with a hard-coded, absolute path in my code. This can be accomplished by packaging the DLL as a “resource” of your application. The whole process becomes a bit tricky though, because you need to first restructure your NetBeans project to accommodate “resource files”, and you also have to deal with the fact that “resource” files CANNOT be loaded as local system libraries in Java. Let me repeat that, a DLL simply cannot be loaded from within a packaged JAR distributable, it needs to be loaded from a file on the system. Here is how I was able to accomplish all this:
1. Create a location to put the DLL within NetBeans project structure
a. Create a new “resources” folder in the “Files” view within NetBeans
i. Create a sub-folder within this folder called “images” or “clibs”
1. Place your DLL files in this directory
b. Go to project properties within NetBeans, and go to “Sources”. Add the “resources” folder you just created and label it anything you want
c. Clean and build your project. Make sure that within the “File” view, the JAR distributable within the “dist” directory contains your newly created “resources” folder.
2. Add code to find the DLL resource within your program, and load the library. Remember, we need to find the DLL resource, copy its contents into a new file located on the local system, and then load that new file as a DLL