Question

I have created an OpenGL project with Scala and JOGL and am trying to package it into a .jar file using sbt and the one-jar plugin.

The .jar is created without any errors, but when I try to run the .jar, I get an error stating that a JOGL .jar within the main .jar cannot be found. I ran jar tf to look at the contents of the main jar, and I see the "missing" jar inside.

The "missing" jar is gluegen-rt-natives-windows-amd64.jar

This is the error I get:

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

This is the output from 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
Was it helpful?

Solution

One-Jar is incomplete, i.e. it does not provide a URL handler for it's jar-in-jar resources.

You can use a "Fat-jar" Layout if you unpack all the jogamp jars and natives:

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

It is also possible to use the Eclipse extended "one-jar" implementation "Export -> Java.Runnable_JAR_file -> Library handling: Package required libraries into generated JAR" this classloader implementation do provide a URL handler for it's jar-in-jar resources.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top