【问题标题】:Configure JOGL with maven使用 maven 配置 JOGL
【发布时间】:2017-12-06 10:37:44
【问题描述】:

我正在尝试按照此处找到的指南使用 maven 配置 JOGL: http://jogamp.org/wiki/index.php/Maven

据我了解应该足以包含这些依赖项:

<dependencies>
    <dependency>
      <groupId>org.jogamp.gluegen</groupId>
      <artifactId>gluegen-rt-main</artifactId>
      <version>2.3.1</version>
    </dependency>
    <dependency>
      <groupId>org.jogamp.jogl</groupId>
      <artifactId>jogl-all-main</artifactId>
      <version>2.3.1</version>
    </dependency>
  </dependencies>

因为他们说:

"So, when you add a dependency on jogl-all-main in your own project, the native jar files of jogl-all are brought in as transitive dependencies and everything works as expected."

我创建了一个包含这些依赖项的 Maven 项目,现在该项目如下所示:

我写了一个简单的 HelloWorld 类来测试它:

import com.jogamp.opengl.GLCapabilities;

    public class HelloWorld {
        public static void main (String args[]) {
            try {


                System.loadLibrary("jogl");
                System.out.println("Hello World! (The native libraries are installed.)");
                GLCapabilities caps = new GLCapabilities(null);
                System.out.println("Hello JOGL! (The jar appears to be available.)");
            } catch (Exception e) {
                System.out.println(e);
            }
        }
    }

但是运行它我得到这个错误:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jogl in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886)
    at java.lang.Runtime.loadLibrary0(Runtime.java:849)
    at java.lang.System.loadLibrary(System.java:1088)
    at jogl.HelloWorld.main(HelloWorld.java:12)

所以似乎没有找到本机 dll(我在 windows 上)。

这里有什么问题? 是教程错了,还是我遗漏了什么?

这是我正在使用的 pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>jogl</groupId>
    <artifactId>jogl</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.jogamp.gluegen</groupId>
            <artifactId>gluegen-rt-main</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.jogamp.jogl</groupId>
            <artifactId>jogl-all-main</artifactId>
            <version>2.3.1</version>
        </dependency>
    </dependencies>
</project>

【问题讨论】:

    标签: maven jogl


    【解决方案1】:

    我发现了问题: 我正在遵循新程序,但使用旧代码加载库。 事实上,有了新库,您就不再需要使用这一行了:

     System.loadLibrary("jogl");
    

    我已经用这个 Line 类对其进行了测试,它可以工作......

    import javax.swing.JFrame;
    
    import com.jogamp.opengl.GL2;
    import com.jogamp.opengl.GLAutoDrawable;
    import com.jogamp.opengl.GLCapabilities;
    import com.jogamp.opengl.GLEventListener;
    import com.jogamp.opengl.GLProfile;
    import com.jogamp.opengl.awt.GLCanvas;
    
    public class Line implements GLEventListener{
       @Override
       public void display(GLAutoDrawable drawable) {
          final com.jogamp.opengl.GL2 gl = drawable.getGL().getGL2();
          gl.glBegin (GL2.GL_LINES);//static field
          gl.glVertex3f(0.50f,-0.50f,0);
          gl.glVertex3f(-0.50f,0.50f,0);
          gl.glEnd();
       }
       @Override
       public void dispose(GLAutoDrawable arg0) {
          //method body
       }
    
       @Override
       public void init(GLAutoDrawable arg0) {
          // method body
       }
       @Override
       public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
          // method body
       }
       public static void main(String[] args) {
          //getting the capabilities object of GL2 profile
          final GLProfile profile = GLProfile.get(GLProfile.GL2);
          GLCapabilities capabilities = new GLCapabilities(profile);
          // The canvas 
          final GLCanvas glcanvas = new GLCanvas(capabilities);
          Line l = new Line();
          glcanvas.addGLEventListener(l);
          glcanvas.setSize(400, 400);
          //creating frame
          final JFrame frame = new JFrame ("straight Line");
          //adding canvas to frame
          frame.getContentPane().add(glcanvas);
          frame.setSize(frame.getContentPane().getPreferredSize());
          frame.setVisible(true);
       }//end of main
    }//end of classimport javax.media.opengl.GL2;
    

    【讨论】:

    • JOGL 1 也不需要此代码,我建议您阅读 JOGL 用户指南。正确设置库路径后,JOGL 1 能够为您加载其本地库。 JOGL 2 引入了自动化的本地库加载;当它工作时,只要包含本机库的 JAR 在类路径中,您就不必设置库路径。顺便说一句,我建议你切换到 JOGL 2.3.2,我记得在以前的小版本中推送到 Maven Central 的 JAR 中缺少一些东西,不要浪费任何时间在我们已经修复的任何错误上。
    • 感谢您的建议。关于代码“System.loadLibrary("jogl");”我在关注这本书:“Learning Java Bindings for OpenGL”,它是从 2004 年开始的,同时规范似乎发生了很大变化......
    • 在 2004 年就已经错了。在我看来,V. Scott Gordon 和 John L. Clevenger 所著的“使用 Java 进行 OpenGL 计算机图形编程”一书要好得多。如果您对 JOGL 有任何非常具体的问题,不如在我们的论坛上提问,StackOverflow 上只有极少数维护者,我们不可能无处不在。
    • 我会看看你推荐的书。谢谢你。当你说“我们的论坛”时,你指的是这个:jogamp.org/forum.html,对吧?
    • 是的,没错,这是官方 JogAmp 论坛:forum.jogamp.org
    猜你喜欢
    • 2010-12-30
    • 2017-02-01
    • 2012-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-08
    • 2011-02-13
    • 1970-01-01
    相关资源
    最近更新 更多