javadll3djava-3d

Java 3D Hello World - Jar freeze


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 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?


Solution

  • 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