2012-11-22 60 views
3

下面的代码从https://sites.google.com/site/justinscsstuff/jogl-tutorial-2为什么这个Java OpenGL(JOGL)程序不能运行?

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

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

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

他使用JOGL 2,在这个版本中没有jogl.jar(jogl.jar来自JOGL 1)。通常,使用jogl-all.jar,并且gluegen-rt.jar也必须位于类路径中。请按照这些说明:http://jogamp.org/wiki/index.php/Setting_up_a_JogAmp_project_in_your_favorite_IDE#Compile_and_run_your_project_from_the_command_line – gouessej

+0

@gouessej好点,更正! :) – Reimeus

+0

感谢您的快速解决。 JOGL 2不再强制设置Java库路径,因为它自动从JAR(jogl-all-natives - *。jar和gluegen-rt-natives - *。jar)中提取本机库当且仅当它们在与其非本地对应目录相同的目录(jogl-all.jar和gluegen-rt.jar)。 – gouessej

1

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

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

+0

原始海报可以简单地用“com.jogamp”替换“javax.media”,使他的代码可以使用最新版本而不是使用过时的代码。包装到ZIP文件中的JAR文件的问题来自某些浏览器,为了“安全”目的将JAR包装到ZIP中,而不是下载包含所有JAR的7z存档或使用包含单个JAR的胖JAR文件的FAT存档。 – gouessej

+0

关于包装,是的,这是真的这个问题。这更多的是对错误消息的响应,这可能发生在用户没有源代码的代码中。 –

+0

@gouessej至于压缩,它有一个.jar扩展名,这很奇怪。 –

相关问题