【问题标题】:Java 3D code giving java.lang.UnsatisfiedLinkErrorJava 3D 代码给出 java.lang.UnsatisfiedLinkError
【发布时间】:2014-08-06 15:44:47
【问题描述】:

我正在尝试运行以下 Java 3D 示例代码。我指的是 3 个罐子和 1 个 dll 文件夹。他们的名字如下:-

  1. vecmath.jar
  2. j3d-core-1.3.1.jar
  3. j3dutils.jar
  4. j3dcore-ogl.dll(我也尝试引用一个 jar 文件而不是这个 dll 文件。jar 文件是 j3dcore-d3d_dll.jar)。

我也尝试将它们放在 jdk 和 jre 的 bin 和 lib 文件夹中。

我还在名为“Path”的系统环境变量中添加了那个 j3dcore-ogl.dll 文件的路径。后来我尝试用 j3dcore-d3d_dll.jar 文件的路径替换它。

代码如下:-

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.GraphicsConfiguration;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.media.j3d.AmbientLight;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.swing.Timer;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;

import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class InteractiveAnimation extends Applet implements ActionListener, KeyListener {

    private static final long serialVersionUID = 1L;

    private Button go = new Button("Go");

  private TransformGroup objTrans;

  private Transform3D trans = new Transform3D();

  private float height = 0.0f;

  private float sign = 1.0f; // going up or down

  private Timer timer;

  private float xloc = 0.0f;

  public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();
    objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objTrans);

    // Create a simple shape leaf node, add it to the scene graph.
    Sphere sphere = new Sphere(0.25f);
    objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D pos1 = new Transform3D();
    pos1.setTranslation(new Vector3f(0.0f, 0.0f, 0.0f));
    objTrans.setTransform(pos1);
    objTrans.addChild(sphere);
    objRoot.addChild(objTrans);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
        100.0);

    Color3f light1Color = new Color3f(1.0f, 0.0f, 0.2f);
    Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
    DirectionalLight light1 = new DirectionalLight(light1Color,
        light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    // Set up the ambient light
    Color3f ambientColor = new Color3f(1.0f, 1.0f, 1.0f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);

    return objRoot;
  }

  public InteractiveAnimation() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse
        .getPreferredConfiguration();
    Canvas3D c = new Canvas3D(config);
    add("Center", c);
    c.addKeyListener(this);
    timer = new Timer(100, this);
    //timer.start();
    Panel p = new Panel();
    p.add(go);
    add("North", p);
    go.addActionListener(this);
    go.addKeyListener(this);
    // Create a simple scene and attach it to the virtual universe
    BranchGroup scene = createSceneGraph();

    SimpleUniverse u = new SimpleUniverse(c);
    u.getViewingPlatform().setNominalViewingTransform();
    u.addBranchGraph(scene);
  }

  public void keyPressed(KeyEvent e) {
    //Invoked when a key has been pressed.
    if (e.getKeyChar() == 's') {
      xloc = xloc + .1f;
    }
    if (e.getKeyChar() == 'a') {
      xloc = xloc - .1f;
    }
  }

  public void keyReleased(KeyEvent e) {
    // Invoked when a key has been released.
  }

  public void keyTyped(KeyEvent e) {
    //Invoked when a key has been typed.
  }

  public void actionPerformed(ActionEvent e) {
    // start timer when button is pressed
    if (e.getSource() == go) {
      if (!timer.isRunning()) {
        timer.start();
      }
    } else {
      height += .1 * sign;
      if (Math.abs(height * 2) >= 1)
        sign = -1.0f * sign;
      if (height < -0.4f) {
        trans.setScale(new Vector3d(1.0, .8, 1.0));
      } else {
        trans.setScale(new Vector3d(1.0, 1.0, 1.0));
      }
      trans.setTranslation(new Vector3f(xloc, height, 0.0f));
      objTrans.setTransform(trans);
    }
  }

  public static void main(String[] args) {
    System.out.println("Program Started");
    InteractiveAnimation bb = new InteractiveAnimation();
    bb.addKeyListener(bb);
    MainFrame mf = new MainFrame(bb, 256, 256);
  }
}

执行此操作时,我得到以下异常堆栈跟踪:-

线程“主”java.lang.UnsatisfiedLinkError 中的异常:java.library.path 中没有 J3D 在 java.lang.ClassLoader.loadLibrary(未知来源) 在 java.lang.Runtime.loadLibrary0(未知来源) 在 java.lang.System.loadLibrary(未知来源) 在 javax.media.j3d.MasterControl$22.run(MasterControl.java:889) 在 java.security.AccessController.doPrivileged(本机方法) 在 javax.media.j3d.MasterControl.loadLibraries(MasterControl.java:886) 在 javax.media.j3d.VirtualUniverse.(VirtualUniverse.java:229) 在 InteractiveAnimation.(InteractiveAnimation.java:84) 在 InteractiveAnimation.main(InteractiveAnimation.java:143)

我应该怎么做才能运行这个程序?

【问题讨论】:

  • 您是否正确安装了Java3D?也就是说,有没有Program Files\Java\Java3D\1.5.1 目录? bin 子目录应该包含 4 个 DLL 文件...
  • 您可以回答自己的问题。如果它是其他答案尚未涵盖的特殊内容,也许对其他人会有所帮助。
  • 其实我只是安装了 Java 3D,而不是使用和管理 jar 和 DLL。为我工作。
  • @Marco13 Java 3D 的最新版本是 11 之前的 1.6 版(2014 年 9 月)。 Java 3D 1.5.1 已经过时了。
  • @gouessej 版本号在这里并不重要,因为问题提到了“任何” pre-jogamp Java3D 版本(显然,它们都是“过时的”)。虽然很高兴看到复兴 Java3D 的努力,但论坛帖子听起来不像是 jogamp 团队真正致力于维护 Java3D,还是有? (在jogamp.orgoracle.com/technetwork/java/javase/tech/index-jsp-138252.htmljava3d.java.net 上没有谈论Java3D 的公共链接也不包含任何信息......)。其实,发现Java3D还不错,所以想在这里看到一个承诺

标签: java eclipse awt java-3d


【解决方案1】:

上面的cmets是完全错误的。 Java 3D 1.3.1 已完全过时,在最新版本的 Java 3D (1.6) 中不再需要手动处理 DLL。我解释如何安装它here

【讨论】:

    【解决方案2】:

    安装 Java 3D(最新版本),而不是放置 jar。

    【讨论】:

    • 抱歉,您的评论不够准确,而且有点误导。 “安装 Java 3D”是什么意思?扩展机制在 Java 1.9 中已被弃用,稍后将被删除,没有办法“安装”Java 库。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-30
    相关资源
    最近更新 更多