UnsatisfiedLinkError indicates that you're missing a native library (usually a .dll
file on Windows, or .so
file on Linux). You'll need to do one of the following:
- Not recommended: Copy the native library to a location on the default java.library.path (on Windows, this includes
C:\Windows\system32
) - Not recommended: Copy the native library to a directory, then run your program with
java -Djava.library.path=dir/containing/library -jar <jarfile>
- Recommended: Bundle the DLL in your jarfile, then modify your code to extract the DLL to a temporary directory and load it using
System.load
orSystem.loadLibrary
.
You can use either of the first two solutions above as a quick hack to get it working, but neither of those solutions is very good. The best solution from a deployment standpoint is #3 above.
In your case, you're using the Lightweight Java Game Library, or lwjgl as referenced in your UnsatisfiedLinkError. So you'll need to include any DLL(s) that come with lwjgl.
When you unzip lwjgl, you'll notice that it has a native directory with a subdirectory for each supported platform. Here is a listing of lwjgl's Windows DLLs:
To implement solution #3 above and make your executable jarfile cross-platform:
- in your project/jarfile, create a separate directory for each platform
- put all the native libraries for each platform in the appropriate directory (it may be helpful to put them in the same directory as some utility class that you'll later use to extract them)
- when you export your program to a jarfile, make sure the native libraries are included
- look up the platform/operating system (e.g., System.getProperty("os.name"))
- in your Java code (probably in your main method or some utility method), create a temporary directory
- for whatever platform you looked up in step 3, extract the appropriate native libraries into the directory you created in step 4 (hint: use
Class.getResourceAsStream
to get anInputStream
, then useFiles.copy
to extract it to a file) - for each library you extract in step 5, call
System.load("path/to/library_file")
See https://stackoverflow.com/a/1611367/44737 for a nice example including code.