嗨,大家好
我正在關注this tutorial來構建我的第一個Java 3D應用程序。我在項目包括java3D libraries和我DllLoader類提取(從classpath中的jar的位置),並加載j3dcore-ogl.dll:Java 3D Hello World - Jar freeze
public class DllLoader {
private DllLoader() {
}
public static void extractAndLoad(String dll) throws IOException {
int aux = dll.lastIndexOf('/');
if (aux == -1) {
aux = dll.lastIndexOf('\\');
}
File dllCopy = new File((aux == -1) ? dll : dll.substring(aux + 1));
try {
System.load(dllCopy.getAbsolutePath());
} catch (UnsatisfiedLinkError e1) {
try {
DllLoader.copyFile(DllLoader.class.getResourceAsStream(dll), dllCopy);
System.load(dllCopy.getAbsolutePath());
} catch (IOException e2) {
}
}
}
private static void copyFile(InputStream pIn, File pOut) throws IOException {
if (!pOut.exists()) {
pOut.createNewFile();
}
DataInputStream dis = new DataInputStream(pIn);
FileOutputStream fos = new FileOutputStream(pOut);
byte[] bytes = new byte[1024];
int len;
while ((len = dis.read(bytes)) > 0) {
fos.write(bytes, 0, len);
}
dis.close();
fos.close();
}
}
一切工作正常,如果我運行從Netbeans項目或如果我打開從命令行與java -jar Hello3DWorld.jar"
罐子。
我的問題是這樣的:如果我用簡單的雙擊運行jar沒有任何反應。該DLL出現在罐子附近,但框架從不出現。
在我的代碼中加入一些JOptionPane.showMessageDialog()
以查明發生了什麼問題,我意識到執行不會引發異常。
加載dll後,它只是在循環中凍結。
你能幫我理解爲什麼它只是通過雙擊jar來掛起,這有什麼問題嗎?