我有一个简单的java项目(改编自这里的例子),如下:
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();
}
}
我的输出是:
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)
我假设这个异常表明libj3dcore-ogl.so
找不到库。这是它的位置:
$ locate libj3dcore-ogl.so
/usr/lib/jni/libj3dcore-ogl.so
如上面的输出所示,/usr/lib/jni
在里面java.library.path
。我究竟做错了什么?(我使用的是 Ubuntu 10.04 和 Eclipse 3.7.2 - 如果这可能是个问题?)
Java 对我来说是一个未知的领域。因此,请在您的笔记/建议/答案上尽可能详细。
更新 1
显然它是一个 64 位库(在 64 位操作系统上):
$ 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
我使用 openjdk 作为运行时环境。java3d( libjava3d-java
) 和 openjdk( openjdk-6-jdk
) 都是通过aptitude
.