Java 3D Hello World - Jar冻结

时间:2011-01-23 18:14:45

标签: java dll 3d java-3d

嗨伙计们 我正在关注this tutorial来构建我的第一个Java 3D应用程序。我在项目中包含java3D libraries和我的 DllLoader 类(从类路径到jar的位置)并加载 j3dcore-ogl.dll :< / p>

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,一切正常。
我的问题是:如果我通过简单的双击运行jar就没有任何事情发生。 dll出现在罐子附近,但框架永远不会出现 在我的代码中加入一些JOptionPane.showMessageDialog()以找出出错的地方,我意识到执行没有异常。
它只是在加载dll 之后就像在循环中冻结一样。你能帮助我理解为什么它只能通过双击jar来挂起,问题是什么?

2 个答案:

答案 0 :(得分:2)

解决了我的问题:D
Windows注册表中有错误... 这是解决方案:
1)运行 regedit
2)找到 HKEY_CLASSES_ROOT\jarfile\shell\open\command
3)确保 javaw.exe 的路径正确

答案 1 :(得分:0)

它甚至可以运行吗?您可能没有正确的文件关联来使用javaw运行jar文件。

有关jar文件关联的信息,请参阅this StackOverflow question