I am running 64 windows. My java version says:
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
My project is GWT Spring project ran on Apache Tomcat server, above java properties apply to the server (this is said to clarify that the server isn't accidentally running different Java version).
In Java code, I use System.getProperty("sun.arch.data.model")
to determine Java version and based on result, I load either 64 or 32 bit dll. In the specific case, I'm now running 64bit and therefore I need 64bit dll file. I placed the file in this location:
D:\programs\apache-tomcat-7.0.64-windows-x64\webapps\war\WEB-INF\lib\MY_LIBRARYx64.dll
In the java code, I have this function to load the library:
private void setLibraryPath_private(String libraryPath) {
// Some magic which doesn't work anyway
File path = new File(configService.getProjectPrefix() + libraryPath);
try {
// Get valid canonical path (special case of absolute path)
path = new File(path.getCanonicalPath());
// Check for readability of that location
if(!path.canRead())
throw new IOException("Cannot read from this file.");
}
catch(IOException e) {
logger.error("Invalid path to R220 library: "+path.getAbsolutePath(), e);
}
// Remember path as string
this.libraryPath = path.getAbsolutePath();
try {
// Load it
library =
(R220) Native.loadLibrary(path.getCanonicalPath(), R220.class);
}
catch(Throwable e) {
// TODO: After loading problem is solved, probably replace throw with the logging
//logger.error("Failed to load R220 library: "+path.getAbsolutePath(), e);
throw new IllegalArgumentException("Failed to load R220 library: "+path.getAbsolutePath(), e);
}
// I don't know what this is
library.initLogger(configService.getLog4cplusConfigFilePath());
}
But in my log I still get error:
[INFO ] 2015-09-21 15:52:26,038 cz.techsys.web.server.R220LibService - Running 64bit version of the native libary.
[ERROR] 2015-09-21 15:52:26,113 cz.techsys.web.server.R220LibService - Failed to load R220 library: D:\programs\apache-tomcat-7.0.64-windows-x64\webapps\war\WEB-INF\lib\MY_LIBRARYx64.dll
java.lang.UnsatisfiedLinkError: Unable to load library 'D:\programs\apache-tomcat-7.0.64-windows-x64\webapps\war\WEB-INF\lib\MY_LIBRARYx64.dll': The specified module could not be found.
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:163)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:236)
at com.sun.jna.Library$Handler.<init>(Library.java:140)
at com.sun.jna.Native.loadLibrary(Native.java:379)
at com.sun.jna.Native.loadLibrary(Native.java:364)
I also checked whether my library really is 64bit. It is, according to this guy:
I also compared it to the 32bit version, which looks like this:
So to sum up:
- Processor architecture matches for the library and Java
- The library is in readable and reachable location
What else can be causing the trouble?
Edit:
Based on some comments here, I also tried to pass library name without extension and set library path through System
:
// Remove name from extension
String name = path.getName().replaceFirst("[.][^.]+$", "");
// Get directory path
String dir = path.getParentFile().getAbsolutePath();
// Print path to console for debug
logger.warn("\n Lib path: "+dir+"\n Lib name:"+name);
// Change library path
System.setProperty("jna.library.path", dir);
// Load it
library =
(R220) Native.loadLibrary(name, R220.class);
Needless to say, this had no effect, except the one that error message is now slightly shorter:
[WARN ] 2015-09-21 16:33:56,819 cz.techsys.web.server.R220LibService -
Lib path: D:\programs\apache-tomcat-7.0.64-windows-x64\webapps\war\WEB-INF\lib
Lib name:WebSightR220libx64
[ERROR] 2015-09-21 16:33:56,882 cz.techsys.web.server.R220LibService - Failed to load R220 library: D:\programs\apache-tomcat-7.0.64-windows-x64\webapps\war\WEB-INF\lib\WebSightR220libx64.dll
java.lang.UnsatisfiedLinkError: Unable to load library 'WebSightR220libx64': The specified module could not be found.
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:163)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:236)