2011-01-23 75 views
3

嗨,大家好
我正在關注this tutorial來構建我的第一個Java 3D應用程序。我在項目包括java3D libraries和我DllLoader類提取(從classpath中的jar的位置),並加載j3dcore-ogl.dllJava 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來掛起,這有什麼問題嗎?

回答

2

解決我的問題:d
有在Windows註冊表中的錯誤... 這是解決方案:
1)運行regedit
2)找到HKEY_CLASSES_ROOT\jarfile\shell\open\command
3)確保路徑爲javaw.exe是正確的

0

它甚至運行?你可能沒有正確的文件關聯來使用javaw運行jar文件。

請參閱this StackOverflow question關於jar文件關聯。