2

我正在按照本教程构建我的第一个 Java 3D 应用程序。我在我的项目中包含了java3D 库和我的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,什么也不会发生。dll 出现在罐子附近,但框架从未出现。

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

4

2 回答 2

2

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

于 2011-01-23T19:04:56.813 回答
0

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

请参阅有关 jar 文件关联的StackOverflow 问题。

于 2011-01-23T19:04:46.097 回答