Linux jogl配置

因为工作需要,这几天在ubuntu下配置jogl,我们知道如果在java中使用一些jar包什么的,都是将这放到CLASSPATH中,但是jogl是需要调Native库的,除了设置CLASSPATH,还需要设置Native库。

 

不同的系统jogl的包的名称是不一样的,下表列出了各个系统上所需要的包,这些可以在

http://jogamp.org/wiki/index.php/Downloading_and_installing_JOGL上找到。

64-bit Windows 64-bit Linux 32/64-bit Mac
gluegen-rt.jar gluegen-rt.jar gluegen-rt.jar
jogl.all.jar jogl.all.jar jogl.all.jar
gluegen-java-src.zip gluegen-java-src.zip gluegen-java-src.zip
jogl-java-src.zip jogl-java-src.zip jogl-java-src.zip
gluegen-rt-natives-windows-amd64.jar gluegen-rt-natives-linux-amd64.jar gluegen-rt-natives-macosx-universal.jar
jogl-all-natives-windows-amd64.jar jogl-all-natives-linux-amd64.jar jogl-all-natives-macosx-universal.jar

 

安装Native 库

 

apt-get install libjogl2-jni

安装之后会有下列文件

 

  • /usr/lib/jni/libjogl_desktop.so
  • /usr/lib/jni/libjogl_mobile.so
  • /usr/lib/jni/libnativewindow_awt.so
  • /usr/lib/jni/libnativewindow_x11.so
  • /usr/lib/jni/libnewt.so
  • /usr/share/doc/libjogl2-jni/changelog.Debian.gz
  • /usr/share/doc/libjogl2-jni/copyright

配置

将jar包配置到CLASSPATH中

 

CLASSPATH=.:$JAVA_HOME/lib.tools.jar:/usr/local/lib/jogl/jogl.all.jar:/usr/local/lib/jogl/gluegen-rt.jar:/usr/local/lib/jogl/jogl-all-natives-linux-amd64.jar

 

将native库配置到放到eclipse的编译参数中。

-Djava.library.path="/usr/local/lib/jogl"

测试代码


import javax.media.opengl.*;


public class HelloWorld {
    public static void main(String[] args) {
        System.out.println(System.getProperty("java.library.path"));
       System.loadLibrary("jogl");
        GLProfile profile = GLProfile.get(GLProfile.GL2ES2);
        GLCapabilities capabilities = new GLCapabilities(profile);
        System.out.println("OK,You do it!");
    }
}

 

如果遇到错误:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jogl in java.library.path
 at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1738)
 at java.lang.Runtime.loadLibrary0(Runtime.java:823)
 at java.lang.System.loadLibrary(System.java:1028)
 at HelloWorld.main(HelloWorld.java:9)
大多数是Native库没配置好。

你可能感兴趣的:(linux)