我想用Java中的默認Windows瀏覽器打開一個URL。不幸的是,我不能使用Desktop類實用程序,因爲代碼必須與1.5兼容。當本地方法的類不在默認包中時UnsatisfiedLinkError java異常
作爲一個解決方案,我用一個本地方法調用ShellExecute的:
public class ShellExec {
public native int execute(String document);
{
System.loadLibrary("HSWShellExec");
}
public static void main(String args[]) throws IOException {
new ShellExec().execute("http://www.google.com/");
}
}
我把DLL文件,在其中顯然包括在的java.library.path Eclipse項目的根。
一切正常,只是完美的,如果ShellExec是默認的包,但是如果我在其他任何包移動,本地調用失敗:
Exception in thread "main" java.lang.UnsatisfiedLinkError: apackage.ShellExec.execute(Ljava/lang/String;)I
at apackage.ShellExec.execute(Native Method)
at apackage.ShellExec.main(ShellExec.java:13)
任何人有任何IDEEA爲什麼呢?我使用的DLL從http://www.heimetli.ch/shellexec.html
感謝
..later編輯:
最終這個類,和其他人,將是一個Eclipse RCP應用程序的實用工具類,以及所有的外部DLL將被放置在java.library.path將指向的常見lib文件夾中。可以看到DLL,但是我得到的錯誤類型與上面的簡單示例類似。
當我這樣做時,兩種方式(包括默認包中的類和非默認包中的類)都會因上述異常而失敗。 – cdmihai 2012-01-06 18:09:19