3

以下代码取自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

关于出了什么问题的任何想法?

4

2 回答 2

4

由于您已经使用 JOGL jar 文件编译了该文件,因此您只需要确保在运行时您的类路径中有这些文件:

java -cp gluegen-rt.jar;jogl-all.jar;. SimpleScene
于 2012-11-22T19:54:55.390 回答
1

您需要使用 JOGL < v2.3,因为包名称已更改。这是v2.2.4 jars的链接。由于某种原因,gluegen-rt.jar 和 jogl-all.jar 实际上是包含真实 jar 的 zip 文件,因此请记住这一点。

我意识到这不是OP 最初发布给出的正确答案,但我遇到了同样的错误,并认为我会帮助下一个人。

于 2016-11-01T06:06:27.123 回答