开发者

Java 3D Hello World - Jar freeze

开发者 https://www.devze.com 2023-02-06 12:45 出处:网络
I am 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 l

I am 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开发者_如何学JAVA is this: if I run the jar with a simple double click, nothing happens. The dll appears near the jar, but the frame never appears.

Putting some JOptionPane.showMessageDialog() in my code to find out what is 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 is the problem?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消