我正在尝试为使用 JOGL 的项目创建一个可执行 jar .以前没有 JOGL,这很容易使用 maven-assembly-plugin。我的应用程序 pom 中有以下内容:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>org.jbox2d.testbed.framework.jogl.JoglTestbedMain</mainClass>
</manifest>
</archive>
</configuration>
在非 jogl 项目中,这会生成一个很好的 jbox2d-testbed-2.2.1.2-SNAPSHOT-jar-with-dependencies
可执行文件(当然,其中有一个不同的主类) .
JOGL 项目在使用 mavin 插件的 Eclipse 中运行得很好,我按照描述包含了 jogl 依赖项 here in the wiki .但是,当我在此项目上使用程序集插件并启动 jbox2d-testbed-jogl-1.0.2-SNAPSHOT-jar-with-dependencies.jar
时,出现以下错误:
Catched FileNotFoundException: /Users/dmurph/Projects/jbox2d/jbox2d-testbed-jogl/target/jbox2d-testbed-jogl-1.0.2-SNAPSHOT-jar-with-dependencies-natives-macosx-universal.jar (No such file or directory), while addNativeJarLibsImpl(classFromJavaJar class com.jogamp.common.os.Platform, classJarURI jar:file:/Users/dmurph/Projects/jbox2d/jbox2d-testbed-jogl/target/jbox2d-testbed-jogl-1.0.2-SNAPSHOT-jar-with-dependencies.jar!/com/jogamp/common/os/Platform.class, nativeJarBaseName jbox2d-testbed-jogl-1.0.2-SNAPSHOT-jar-with-dependencies-natives-macosx-universal.jar): [ file:/Users/dmurph/Projects/jbox2d/jbox2d-testbed-jogl/target/jbox2d-testbed-jogl-1.0.2-SNAPSHOT-jar-with-dependencies.jar -> file:/Users/dmurph/Projects/jbox2d/jbox2d-testbed-jogl/target/ ] + jbox2d-testbed-jogl-1.0.2-SNAPSHOT-jar-with-dependencies-natives-macosx-universal.jar -> slim: jar:file:/Users/dmurph/Projects/jbox2d/jbox2d-testbed-jogl/target/jbox2d-testbed-jogl-1.0.2-SNAPSHOT-jar-with-dependencies-natives-macosx-universal.jar!/
Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: /System/Library/Frameworks/gluegen-rt.Framework/gluegen-rt
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1854)
at java.lang.Runtime.load0(Runtime.java:795)
at java.lang.System.load(System.java:1062)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLoaderBase.java:551)
at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.java:64)
at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JNILibLoaderBase.java:96)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase.java:414)
at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrary(DynamicLibraryBundle.java:388)
at com.jogamp.common.os.Platform$1.run(Platform.java:203)
at java.security.AccessController.doPrivileged(Native Method)
at com.jogamp.common.os.Platform.<clinit>(Platform.java:173)
at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:82)
at org.jbox2d.testbed.framework.jogl.JoglPanel.<init>(JoglPanel.java:52)
at org.jbox2d.testbed.framework.jogl.JoglTestbedMain.main(JoglTestbedMain.java:62)
当我解压缩 jar 时,我看到了 JOGL 所需的所有 dll 和 jnilib 库,那么我需要做一些额外的事情才能让它工作吗?我知道 JOGL 使用单独的 jar 系统,我是否需要更改程序集插件的行为以便它可以正确生成额外的 jar?
如果您愿意,可以获取我的项目并尝试一下,它位于 https://github.com/dmurph/jbox2d。
谢谢!
最佳答案
根据JOGL FAQ ,您需要将 native 库放在 fat jar 中的特定位置。看起来你在 Mac 上,所以你需要将你的本地库放在这个目录中在你的 jar 中:
natives/macosx-universal/
如@gouessej 所述,here is a complete list of supported architectures and required directories .
我认为您需要创建自定义 Assembly Descriptor :
https://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
编写您自己的描述符将使您能够将 jar 放置在特定位置,以获得您需要的包装。
关于java - 使用带有 JOGL 的 maven assembly 插件创建可执行 jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21744714/