How can I load a custom dll file in my web application? I’ve tried the following:
- Copied all required dlls in
system32folder and tried to load one of them inServletconstructorSystem.loadLibrary - Copied required dlls into
tomcat_home/shared/libandtomcat_home/common/lib
All these dlls are in WEB-INF/lib of the web-application
In order for
System.loadLibrary()to work, the library (on Windows, a DLL) must be in a directory somewhere on yourPATHor on a path listed in thejava.library.pathsystem property (so you can launch Java likejava -Djava.library.path=/path/to/dir).Additionally, for
loadLibrary(), you specify the base name of the library, without the.dllat the end. So, for/path/to/something.dll, you would just useSystem.loadLibrary("something").You also need to look at the exact
UnsatisfiedLinkErrorthat you are getting. If it says something like:then it can’t find the foo library (foo.dll) in your
PATHorjava.library.path. If it says something like:then something is wrong with the library itself in the sense that Java is not able to map a native Java function in your application to its actual native counterpart.
To start with, I would put some logging around your
System.loadLibrary()call to see if that executes properly. If it throws an exception or is not in a code path that is actually executed, then you will always get the latter type ofUnsatisfiedLinkErrorexplained above.As a sidenote, most people put their
loadLibrary()calls into a static initializer block in the class with the native methods, to ensure that it is always executed exactly once: