为什么不将这个Java的OpenGL(JOGL)程序运行?(Why won't this J

2019-07-04 01:44发布

下面的代码从被采取https://sites.google.com/site/justinscsstuff/jogl-tutorial-2

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;

public class SimpleScene {
    public static void main(String[] args) {
        GLProfile glp = GLProfile.getDefault();
        GLCapabilities caps = new GLCapabilities(glp);
        GLCanvas canvas = new GLCanvas(caps);

        Frame frame = new Frame("AWT Window Test");
        frame.setSize(300, 300);
        frame.add(canvas);
        frame.setVisible(true);

        // by default, an AWT Frame doesn't do anything when you click
        // the close button; this bit of code will terminate the program when
        // the window is asked to close
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }
}

它编译没有任何问题,但是当我使用

java SimpleScene

我得到以下错误

C:\Users\Mitc\Drive\Google Drive\Game\Display>java SimpleScene
Exception in thread "main" java.lang.NoClassDefFoundError: javax/media/opengl/GLCapabilitiesImmutable
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.media.opengl.GLCapabilitiesImmutable
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 6 more

任何想法是什么问题呢?

Answer 1:

正如你已经编译JOGL的jar文件的文件,你只需要确保你在运行时在你的classpath这些文件:

java -cp gluegen-rt.jar;jogl-all.jar;. SimpleScene


Answer 2:

您需要使用JOGL <V2.3,因为包名称改变。 下面是该链接V2.2.4罐子 。 出于某种原因,gluegen-rt.jar中和JOGL-all.jar在实际上被压缩含有真正的罐子文件,所以记住这一点。

我知道这是不是 OP最初发布给出了正确的答案,但我遇到了同样的错误,我想我会帮忙下一个人。



文章来源: Why won't this Java OpenGL (JOGL) program run?
标签: java opengl jogl