Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WorldWind - Runnable jar : no gluegen-rt in java.library.path

I'm working with WorldWind Java and Eclipse.

I am trying to export a runnable jar from my project in Eclipse. The export goes well but when I try to run the jar I got this error :

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.UnsatisfiedLinkError: no gluegen-rt in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
    at java.lang.Runtime.loadLibrary0(Runtime.java:840)
    at java.lang.System.loadLibrary(System.java:1047)
    at com.sun.gluegen.runtime.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:102)
    at com.sun.gluegen.runtime.NativeLibLoader.access$000(NativeLibLoader.java:51)
    at com.sun.gluegen.runtime.NativeLibLoader$1.run(NativeLibLoader.java:70)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.gluegen.runtime.NativeLibLoader.loadGlueGenRT(NativeLibLoader.java:68)
    at com.sun.gluegen.runtime.NativeLibrary.ensureNativeLibLoaded(NativeLibrary.java:399)
    at com.sun.gluegen.runtime.NativeLibrary.open(NativeLibrary.java:163)
    at com.sun.gluegen.runtime.NativeLibrary.open(NativeLibrary.java:129)
    at com.sun.opengl.impl.x11.DRIHack.begin(DRIHack.java:109)
    at com.sun.opengl.impl.x11.X11GLDrawableFactory.<clinit>(X11GLDrawableFactory.java:99)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:186)
    at javax.media.opengl.GLDrawableFactory.getFactory(GLDrawableFactory.java:111)
    at javax.media.opengl.GLCanvas.chooseGraphicsConfiguration(GLCanvas.java:520)
    at javax.media.opengl.GLCanvas.<init>(GLCanvas.java:131)
    at javax.media.opengl.GLCanvas.<init>(GLCanvas.java:90)
    at gov.nasa.worldwind.awt.WorldWindowGLCanvas.<init>(Unknown Source)

I can run the project within Eclipse without any problem, I have worldwind.jar, jogl.jar, gluegen-rt.jar and gluegen-rt-natives-linux-amd64.jar referenced in the build path with the native libraries .so files location. For now the project is just a JFrame displaying a WorldWind globe as in gov.nasa.worldwindx.examples.SimplestPossibleExample.java.

I am trying to build an application that would run on several OS.

What am I doing wrong for my jar not being able to run while I can run the project without problem within Eclipse ?

I think I have a problem in the process of exporting a jar with native libraries but after looking for it on Google I can't find a solution to this.

I am running on Linux 64 bits with OpenJDK.

Thanks.


Edit :

I found a workaround that makes it work, but not the way I'd like it to:

It seems Eclipse's "Export Runnable Jar ... " doesn't export .so files in a way that makes them accessible when I run the jar, while the requiered .jar files are included in the exported .jar and are reachable.

The solution was to include .so files (these would be .jnilib for Mac and .dll for Windows) in a folder next to the jar and lauching the jar with the following command line : java -Xmx512m -Dsun.java2d.noddraw=true -Djava.library.path=./lib -jar MyJAR.jar

-Xmx512m is increasing java memory because WorldWind may need more memory than the default amount, -Dsun.java2d.noddraw=true can avoid some displaying errors IIRC.

I made a .bash and a .bat files containing this command line.

From what I found, it doesn't seem setting the lib location is requiered on Windows as long as the .dll files are in the same folder as the .jar, though on Linux it is always needed. Since I put the libraries in a lib folder wich is in the same folder as the .jar, I need to set -Djava.library.path in both cases.

The required libraries for Linux are : libgluegen-rt.so libjogl.so libjogl_awt.so

I found those here : http://download.java.net/media/jogl/builds/archive/

Now the exported jar runs fine on my Lunix 64 bits system and I am currently trying to find a Windows and a Mac system to test it out.

If anyone has a solution to access .so files that are inside the .jar file, this is still welcome.

like image 524
Autar Avatar asked Nov 14 '22 04:11

Autar


1 Answers

Have you looked at one-jar. It has a system for packing native libs into an application jar.

http://one-jar.sourceforge.net/index.php?page=details&file=native

like image 59
pfranza Avatar answered Nov 16 '22 02:11

pfranza