Java 3D Hello World - Jar 卡住

标签 java dll 3d java-3d

我正在关注 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 才会挂起吗?问题是什么?

最佳答案

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

关于Java 3D Hello World - Jar 卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4775487/

相关文章:

Java 3D 游戏引擎?

java - 在 Java 调试 session 期间查找大字符串分配

java - 骰子直方图

java - 使用 x86javapath 的 x64 机器上的 x86java 上的 JNI 不满足链接错误

windows - 启动应用程序时 jvm.dll 丢失错误

scala - 如何使用 2d GUI (nifty-gui) 正确渲染 3d 对象?

iphone - 适用于 iOS 的 3D 对象/增强现实库

java - "opening"Android设备中的网站

java - 如何解决 ClassNotFoundException?

c++ - 在 CMake 项目中传递复制 dll