3

The following code was taken from 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);
            }
        });
    }
}

It compiles without any problems, but when I use

java SimpleScene

I get the following error

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

Any ideas as to what is going wrong?

2 Answers 2

4

As you have already compiled the file with JOGL jar files, you just need to make sure that you have these files in your classpath at runtime:

java -cp gluegen-rt.jar;jogl-all.jar;. SimpleScene
Sign up to request clarification or add additional context in comments.

2 Comments

He uses JOGL 2, there is no jogl.jar in this version (jogl.jar comes from JOGL 1). Generally, jogl-all.jar is used and gluegen-rt.jar must be in the classpath too. Rather follow these instructions: jogamp.org/wiki/index.php/…
Thank you for the quick fix. Setting the Java library path is no longer mandatory with JOGL 2 as it automatically extracts the native libraries from the JARs (jogl-all-natives-.jar and gluegen-rt-natives-.jar) if and only if they are in the same directory than their non native counterparts (jogl-all.jar and gluegen-rt.jar).
1

You need to use JOGL < v2.3 because the package names changed. Here's a link to the v2.2.4 jars. For some reason gluegen-rt.jar and jogl-all.jar were actually zip files which contained the real jars, so keep that in mind.

I realize this isn't the correct answer given when the OP originally posted, but I encountered the same error and thought I'd help out the next person.

7 Comments

The original poster can simply replace "javax.media" by "com.jogamp" to make his code work with the latest version instead of using an obsolete one. The problems of JAR files wrapped into ZIP files come from some web browsers wrapping JARs into ZIPs for "security" purposes, rather download the 7z archive containing all JARs or use the fat archive containing a single fat JAR for JogAmp.
Regarding the packages, yes, that's true for this question. This was more a response to the error message, which might occur in code the user doesn't have the source for.
@gouessej As for the zipping, it has a .jar extension, which was weird.
I know that it's weird, that's the main reason why I put my own fat JAR (of my game) into a native bundle. Mozilla Firefox under Windows did it in the past (JAR -> ZIP named as JAR) but I thought that it was a thing of the past.
It seems to be the behaviour in Chrome, Firefox, and Midori on my computer, but wget did give me a proper jar so, yeah, it is just the browser. It really should drop a .zip extension on them...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.