2

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?

peterh
  • 11,875
  • 18
  • 85
  • 108
Oneiros
  • 4,328
  • 6
  • 40
  • 69

2 Answers2

2

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

Oneiros
  • 4,328
  • 6
  • 40
  • 69
0

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.

Community
  • 1
  • 1
Jonathon Faust
  • 12,396
  • 4
  • 50
  • 63