Java 3D Hello World - Jar freeze

社会主义新天地 提交于 2020-01-02 07:30:13

问题


Hi guys
I'm following this tutorial to build my first Java 3D application. I included in my project the java3D libraries and my DllLoader class that extracts (from the classpath to the jar's location) and loads the j3dcore-ogl.dll:

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();
    }
}


Everything works fine if I run the project from Netbeans or if i open the jar from the command line with java -jar Hello3DWorld.jar".
My problem is this: if I run the jar with a simple double click nothing happens. The dll appear near the jar but the frame never appear.
Putting some JOptionPane.showMessageDialog() in my code to find out what's going wrong, I realized that the execution throws no exception.
It just freezes like in a loop after loading the dll.
Can you help me to understand why it hangs only by double clicking the jar and what's the problem?


回答1:


Solved my problem :D
There were an error in the Windows Registry... this is the solution:
1) run regedit
2) find HKEY_CLASSES_ROOT\jarfile\shell\open\command
3) make sure the path for javaw.exe is correct




回答2:


Does it even run? You could just not have the right file association to run jar files using javaw.

See this StackOverflow question regarding jar file association.



来源:https://stackoverflow.com/questions/4775487/java-3d-hello-world-jar-freeze

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!