I've built a jar through netbeans, specifying my main class and libraries. In the properties section, I have the library in the Libraries section and I've set
-Djava.library.path=/path/to/lib
in the Run section. However, when I run the jar file through the command line using
java -jar
it returns the error
java.lang.UnsatisfiedLinkError: no libName in java.library.path
There is a lib directory in the same directory as my jar file, with the library in it, and the manifest file in the jar contains
Class-Path: lib/libName.jar
What's wrong with my jar file?
java.library.path
isn't used for loading jar
-files but for loading native libraries used by eg JNI. From the error message it seems your application is calling System.loadLibrary("libName")
, so your system is looking for libName.dll
(on Windows) or libName.so
(on Unix) which aren't there.
If you only have some classes in libName.jar
you have no need for System.loadLibrary()
nor for java.library.path
- just include libName.jar
in your classpath and java will find everything it needs.
If libName.jar
contains native libraries you want to use: there's no straightforward way to load dll
s or so
s from inside a jar
without unpacking them first, so the easiest way is to put the native library outside the jar as an extra file in your /lib
-directory. There are also libraries out there that allow you to use the native lib from inside a jar - see this question for more info.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.