运行JOGL项目打包为.jar时找不到路径

时间:2013-05-23 17:56:27

标签: java sbt jogl onejar

我用Scala和JOGL创建了一个OpenGL项目,并尝试使用sbt和one-jar插件将其打包成.jar文件。

创建.jar没有任何错误,但是当我尝试运行.jar时,我收到一条错误,指出主.jar中的JOGL .jar无法找到。我跑jar tf来查看主jar的内容,我看到里面有“丢失”的jar。

“缺失”的jar是gluegen-rt-natives-windows-amd64.jar

这是我得到的错误:

Catched FileNotFoundException: \target\scala-2.9.2\rings_2.9.2-1.0-one-jar.jar (
The system cannot find the path specified), while TempJarCache.bootstrapNativeLi
b() of jar:file:/target/scala-2.9.2/rings_2.9.2-1.0-one-jar.jar!/lib/gluegen-rt-
natives-windows-amd64.jar!/ (file:/target/scala-2.9.2/rings_2.9.2-1.0-one-jar.ja
r!/lib/ + gluegen-rt-natives-windows-amd64.jar)
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.simontuffs.onejar.Boot.run(Boot.java:340)
    at com.simontuffs.onejar.Boot.main(Boot.java:166)
Caused by: java.lang.UnsatisfiedLinkError: no gluegen-rt in java.library.path
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at com.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLoad
        erBase.java:442)
    at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.ja
        va:59)
    at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JNIL
        ibLoaderBase.java:90)
    at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase.j
         ava:328)
    at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrar
         y(DynamicLibraryBundle.java:390)
    at com.jogamp.common.os.Platform.loadGlueGenRTImpl(Platform.java:251)
    at com.jogamp.common.os.Platform.access$000(Platform.java:57)
    at com.jogamp.common.os.Platform$1.run(Platform.java:186)
    at com.jogamp.common.os.Platform$1.run(Platform.java:183)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.jogamp.common.os.Platform.<clinit>(Platform.java:183)
    at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:82)
    at com.bwroga.opengl.GLEnvironment.createCanvas(GLEnvironment.scala:63)
    at com.bwroga.opengl.GLEnvironment.<init>(GLEnvironment.scala:18)
    at Environment.<init>(Main.scala:24)
    at Main$.<init>(Main.scala:12)
    at Main$.<clinit>(Main.scala)
    at Main.main(Main.scala)
    ... 6 more

这是jar tf的输出:

META-INF/MANIFEST.MF
com/
com/simontuffs/
com/simontuffs/onejar/
doc/
lib/
main/
com/simontuffs/onejar/JarClassLoader$2.class
lib/scala-library.jar
lib/gluegen-rt-natives-linux-amd64.jar
.version
lib/jogl-all-natives-macosx-universal.jar
com/simontuffs/onejar/JarClassLoader$OneJarURLFactory.class
com/simontuffs/onejar/JarClassLoader.class
com/simontuffs/onejar/OneJarFile.class
boot-manifest.mf
com/simontuffs/onejar/OneJarURLConnection.class
lib/jogl-all-natives-linux-amd64.jar
lib/gluegen-rt-natives-windows-i586.jar
com/simontuffs/onejar/Boot$1.class
com/simontuffs/onejar/IProperties.class
com/simontuffs/onejar/Handler.class
com/simontuffs/onejar/Handler$1.class
lib/jogl-all.jar
main/rings_2.9.2-1.0.jar
com/simontuffs/onejar/Boot$3.class
lib/commons-lang-2.6.jar
doc/one-jar-license.txt
lib/gluegen-rt-natives-macosx-universal.jar
OneJar.class
com/simontuffs/onejar/OneJarFile$1.class
com/simontuffs/onejar/JarClassLoader$1.class
com/simontuffs/onejar/JarClassLoader$IURLFactory.class
com/simontuffs/onejar/JarClassLoader$ByteCode.class
lib/jogl-all-natives-windows-amd64.jar
com/simontuffs/onejar/JarClassLoader$FileURLFactory$1.class
com/simontuffs/onejar/JarClassLoader$FileURLFactory.class
lib/jogl-all-natives-windows-i586.jar
lib/gluegen-rt.jar
com/simontuffs/onejar/Boot$2.class
lib/jogl-all-natives-linux-i586.jar
com/simontuffs/onejar/Boot.class
lib/gluegen-rt-natives-linux-i586.jar
lib/gluegen-rt-natives-windows-amd64.jar
com/simontuffs/onejar/OneJarFile$2.class

1 个答案:

答案 0 :(得分:2)

One-Jar不完整,即它没有为它的jar-in-jar资源提供URL处理程序。

你可以使用“胖子” 如果您解压缩所有jogamp jar和natives的布局:

 /com/lala1/Lala1.class
 /com/lala2/Lala2.class
 /natives/<os.and.arch>/libLala1.so
 /natives/<os.and.arch>/libLala2.so

还可以使用Eclipse扩展的“one-jar”实现“Export - &gt; Java.Runnable_JAR_file - &gt;库处理:将所需的包打包到生成的JAR中” 这个类加载器实现确实为它的jar-in-jar资源提供了一个URL处理程序。

https://jogamp.org/wiki/index.php/JogAmp_JAR_File_Handling