我编写了一个使用 JACOB 访问 iTunes 的程序...它在 Eclipse 中工作正常,但是当我导出它并在命令提示符中运行它时,我收到一个不满意的链接错误,告诉我 jacob-1.17-M2-x86.dll 是不在我的 java.library.path 中。
我尝试将其放入 system32 中,将本机库位置设置为其目录...我尝试使用 system.setproperties 技巧...但我无法弄清楚如何正确使用 java -d
我还可以做些什么?我在网上搜索了 4 个多小时试图获得此兼容,但似乎没有任何效果。
我发现 Sun 程序员发表的一篇很棒的文章解决了我的问题!
public static void addDir(String s) throws IOException {
try {
// This enables the java.library.path to be modified at runtime
// From a Sun engineer at http://forums.sun.com/thread.jspa?threadID=707176
Field field = ClassLoader.class.getDeclaredField("usr_paths");
field.setAccessible(true);
String[] paths = (String[])field.get(null);
for (int i = 0; i < paths.length; i++) {
if (s.equals(paths[i])) {
return;
}
}
String[] tmp = new String[paths.length+1];
System.arraycopy(paths,0,tmp,0,paths.length);
tmp[paths.length] = s;
field.set(null,tmp);
System.setProperty("java.library.path", System.getProperty("java.library.path") + File.pathSeparator + s);
} catch (IllegalAccessException e) {
throw new IOException("Failed to get permissions to set library path");
} catch (NoSuchFieldException e) {
throw new IOException("Failed to get field handle to set library path");
}
}
然后我在使用 JACOB 方法之前添加
addDir("C:" + File.separator + "java" + File.separator + "jre7" + File.separator + "lib")
工作起来就像一个魅力。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)