I have a simple java project (adapted from the example here), which is as follows:
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.geometry.ColorCube;
import javax.media.j3d.BranchGroup;
public class HelloWorld {
public HelloWorld()
{
SimpleUniverse universe = new SimpleUniverse();
BranchGroup group = new BranchGroup();
group.addChild(new ColorCube(0.3));
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(group);
}
public static void main(String[] args) {
System.out.println("Hello World!");
System.out.println("PATH : " + System.getProperty("java.library.path"));
new HelloWorld();
}
}
My output is:
Hello World!
PATH : /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server:/usr/lib/jvm/java-6-openjdk/jre/lib/amd64:/usr/lib/jvm/java-6-openjdk/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib/jni:/lib:/usr/lib
Exception in thread "main" java.lang.UnsatisfiedLinkError: no j3dcore-ogl 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 javax.media.j3d.NativePipeline$1.run(NativePipeline.java:231)
at java.security.AccessController.doPrivileged(Native Method)
at javax.media.j3d.NativePipeline.loadLibrary(NativePipeline.java:200)
at javax.media.j3d.NativePipeline.loadLibraries(NativePipeline.java:157)
at javax.media.j3d.MasterControl.loadLibraries(MasterControl.java:987)
at javax.media.j3d.VirtualUniverse.<clinit>(VirtualUniverse.java:299)
at HelloWorld.<init>(HelloWorld.java:10)
at HelloWorld.main(HelloWorld.java:20)
I assume this Exception indicates that the library libj3dcore-ogl.so
could not be found. Here's where it is located:
$ locate libj3dcore-ogl.so
/usr/lib/jni/libj3dcore-ogl.so
As the output above shows, /usr/lib/jni
is inside java.library.path
. What am I doing wrong? (I'm using Ubuntu 10.04 and Eclipse 3.7.2 - if that may be an issue?)
Java is a bit of unknown territory for me. So please be as verbose as possible on your notes/suggestions/answers.
Update 1
Apparantly it's a 64-bit library (on a 64-bit operating system):
$ file /usr/lib/jni/libj3dcore-ogl.so
/usr/lib/jni/libj3dcore-ogl.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, stripped
I use openjdk as runtime environment. Both java3d (libjava3d-java
) and the openjdk (openjdk-6-jdk
) is installed via aptitude
.
Interestingly, it works if I compile and run the application from my terminal:
javac -classpath /usr/share/java/j3dcore.jar:/usr/share/java/j3dutils.jar:/usr/share/java/vecmath-1.5.2.jar:. HelloWorld.java
java -classpath /usr/share/java/j3dcore.jar:/usr/share/java/j3dutils.jar:/usr/share/java/vecmath-1.5.2.jar:. HelloWorld
But I would really like to use eclipse to do this kind of things.
$ java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.13) (6b20-1.9.13-0ubuntu1~10.04.1)
OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)
It also works with Eclipse, if I copy the native library (libj3dcore-ogl.so
) to the jvm directory and add the libraries (j3dcore.jar
, j3dutils.jar
, vecmath-1.5.2.jar
) as external jars to the build path libraries (right click on project -> Properties -> Java Build Path -> Libraries -> Add External JARs...):
sudo cp /usr/lib/jni/libj3dcore-ogl.so /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/
But I wonder if there really is no solution that wouldn't require this copy.