2013-04-11 80 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") 

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