I'm trying to load a DLL with a static block on my servlet definition like this:
String ehrViewerExternalNativeLibs = "webapps" + pathSeparator +
"ehr-viewer" + pathSeparator +
"WEB-INF" + pathSeparator +
"classes" + pathSeparator +
"extlib";
try {
String catalinaHome = System.getProperty("catalina.home");
String defaultLibraryPath = System.getProperty("java.library.path");
String sharedLibraryPath = catalinaHome + pathSeparator + ehrViewerExternalNativeLibs;
if (catalinaHome != null) {
System.setProperty("java.library.path", defaultLibraryPath + ";" + sharedLibraryPath);
String curPath = System.getProperty("java.library.path");
logger.info(curPath);
System.loadLibrary("awj2k");
//System.load(sharedLibraryPath + "\\awj2k.dll");
Class.forName("com.aware.j2k.codec.engine.AwJ2k");
}
I keep getting an error like this:
Mar 10, 2015 11:17:27 AM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Allocate exception for servlet ehrViewerServiceImpl
java.lang.UnsatisfiedLinkError: no awj2k in java.library.path at java.lang.ClassLoader.loadLibrary(Unknown Source) at java.lang.Runtime.loadLibrary0(Unknown Source) at java.lang.System.loadLibrary(Unknown Source) at com.softmedical.ehrviewer.server.EHRViewerServiceImpl.(EHRViewerServiceImpl.java:121)
The output for the library path is :
INFO | 2015-03-10 11:17:27,558 | - D:\Tomcat-7.0\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;;.;D:\Tomcat-7.0\webapps\ehr-viewer\WEB-INF\classes\extlib
And the content of folder extlib is
awj2k.dll
If I put the DLL in D:\Tomcat-7.0\bin it works just fine. What dark spell is going behind the curtains? Why can I load a DLL from the place I want? I see the java.library.path is set correctly so why is it not working?