【问题标题】:Java 3D Hello World - Jar freezeJava 3D Hello World - Jar 冻结
【发布时间】:2011-01-23 18:14:45
【问题描述】:

我正在关注this tutorial 来构建我的第一个 Java 3D 应用程序。我在我的项目中包含了java3D libraries 和我的DllLoader 类,该类提取(从类路径到jar 的位置)并加载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();
    }
}

如果我从 Netbeans 运行项目,或者我从命令行使用 java -jar Hello3DWorld.jar" 打开 jar,一切正常。

我的问题是这样的:如果我通过简单的双击运行 jar,什么都不会发生。 dll 出现在 jar 附近,但框架从未出现。

在我的代码中添加一些JOptionPane.showMessageDialog() 以找出问题所在,我意识到执行不会引发异常。它只是在加载 dll 后像循环一样冻结。你能帮我理解为什么它只通过双击 jar 就挂起吗?问题是什么?

【问题讨论】:

    标签: java dll 3d java-3d


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-12-14
        • 2015-04-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多