我正在运行64个窗口。我的java版本说:
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)
我的项目是GWT Spring项目在Apache Tomcat服务器上运行,上面的java属性适用于服务器(据说澄清了服务器不小心运行不同的Java版本)。
在Java代码中,我使用System.getProperty("sun.arch.data.model")
来确定Java版本,并根据结果,加载64位或32位dll。在具体情况下,我现在运行64位,因此我需要64位dll文件。我把文件放在这个位置:
D:\programs\apache-tomcat-7.0.64-windows-x64\webapps\war\WEB-INF\lib\MY_LIBRARYx64.dll
在java代码中,我有这个函数来加载库:
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());
}
但是在我的日志中我仍然会收到错误:
[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)
我还检查了我的库是否真的是64位。根据{{3}}:
我还将它与32位版本进行了比较,如下所示:
总结一下:
还有什么可能导致麻烦?
修改
根据这里的一些评论,我还试图传递没有扩展名的库名,并通过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);
毋庸置疑,除了错误消息现在稍微短一点之外,这没有任何效果:
[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)