2013-04-11 81 views
0

我把一个程序,使用JACOB访问iTunes ...它在Eclipse中工作正常,但是当我导出它并在命令提示符下运行时,我得到一个不满意的链接错误告诉我,雅各布-1.17-M2-x86.dll不在我的java.library.path中。UnsatisfiedLinkError与JACOB和JRE 1.7

伊夫试图把它在system32下,设置本机库的位置对其目录...使用system.setproperties招我用尽...和我不能弄清楚如何使用Java -D正确

什么我能做什么?我一直在寻找网络试图让这个兼容超过4小时,似乎没有任何工作。

回答

0

我发现了一个太阳程序员的一个惊人的职位,解决了我的问题!

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") 

工作就像一个魅力前加入。