2011-01-23 76 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文件关联。