Linux java3D lib 配置的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4098161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 23:53:14  来源:igfitidea点击:

problems with java3D lib configuration

javalinuxeclipseexceptionjava-3d

提问by JB87

ive ran into some trouble configuring java3D to work with my IDE environment...

我在配置 java3D 以与我的 IDE 环境一起工作时遇到了一些麻烦......

I have downloaded j3d-1_5_2-linux-i586.zip, and unpacked j3dcore.jar, j3dutils.jar, vecmath.jar, libj3dcore-ogl.so, libj3dcore-ogl-cg.so and added them all as 'Referenced Libraries' within my project folder. this gets rid of any compilation warnings I was getting but when I compile and run the application I get the following exception!

我已经下载了 j3d-1_5_2-linux-i586.zip,并解压了 j3dcore.jar、j3dutils.jar、vecmath.jar、libj3dcore-ogl.so、libj3dcore-ogl-cg.so 并将它们全部添加为“参考库”我的项目文件夹。这消除了我收到的任何编译警告,但是当我编译并运行应用程序时,我收到以下异常!

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.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 Hello3d.<init>(Hello3d.java:10)
    at Hello3d.main(Hello3d.java:18)

here is a quick look at the source code as well. NOTE: Eclipse pulled in the import libraries paths automatically with Ctrl+Shift+O once they were added as Referenced Libraries.

这里也快速浏览一下源代码。注意:一旦将导入库路径添加为引用库,Eclipse 就会使用 Ctrl+Shift+O 自动拉入导入库路径。

import javax.media.j3d.BranchGroup;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class Hello3d {

    public Hello3d(){
        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){
        new Hello3d();
    }
}

im not sure what im meant to do with 'j3dcore-ogl' but im stuck at this point. how do you install java3D within the system environment or the IDE project? please help.

我不确定我对'j3dcore-ogl'的意思是什么,但我在这一点上卡住了。你如何在系统环境或IDE项目中安装java3D?请帮忙。

IDE: Eclipse SDK 3.5.2

IDE:Eclipse SDK 3.5.2

JVM: java-6-sun-1.6.0.22

JVM:java-6-sun-1.6.0.22

OS: Ubuntu 10.04 LTS

操作系统:Ubuntu 10.04 LTS

回答by JohnnyO

Java is complaining because it cannot find the native libraries (the *.so files) on your system path that Java3D comes with. Exactly how you fix this is up to you. You can do anyone one of the following:

Java 抱怨是因为它在您的系统路径上找不到 Java3D 附带的本机库(*.so 文件)。究竟如何解决这个问题取决于您。您可以执行以下任一操作:

1) Make sure that your system path includes the *.so files provided with Java3D

1) 确保您的系统路径包含 Java3D 提供的 *.so 文件

2) Setup your LD_LIBRARY_PATH environment variable: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/"path-to-java3d-libraries"/

2) 设置你的 LD_LIBRARY_PATH 环境变量: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/"path-to-java3d-libraries"/

3) Set the java.library.path when executing java: java -Djava.library.path=$LD_LIBRARY_PATH:/usr/lib/"path-to-java3d-libraries"/

3)在执行java时设置java.library.path:java -Djava.library.path=$LD_LIBRARY_PATH:/usr/lib/"path-to-java3d-libraries"/

To be sure you have things set correctly, add the following to your Java code and make sure the path reported contains the shared libraries on it

为确保设置正确,请将以下内容添加到 Java 代码中,并确保报告的路径包含共享库

System.out.println("LD Library Path:" + System.getProperty("java.library.path"));

回答by Mahdi_Nine

I had this problem.

我有这个问题。

it is enough you download java3d plugin and install it.

你下载java3d插件并安装它就足够了。

in your search engine like Google search "java3d plugin"

在您的搜索引擎中,例如 Google 搜索“java3d 插件”

and download so install it.

并下载安装它。

回答by telman shahbazov

project/properties/java build path/source tab/expand and select native library location / navigate to i386 folder.

项目/属性/java 构建路径/源选项卡/展开并选择本机库位置/导航到 i386 文件夹。

回答by markoz

I know this question is now a few years old, but the answers here were not enough for me to solve the problem. They only helped partially. http://www.filsa.net/2008/07/17/eclipse-java3d-and-javalibrarypath/was also a bit helpful, but it was still not enough. Therefore I felt obliged to write a complete checklist to have Java3D work in Eclipse.

我知道这个问题现在已经有几年了,但是这里的答案还不足以让我解决这个问题。他们只提供了部分帮助。http://www.filsa.net/2008/07/17/eclipse-java3d-and-javalibrarypath/也有点帮助,但还是不够。因此我觉得有必要写一个完整的清单来让 Java3D 在 Eclipse 中工作。

A few months ago, I already had the same problem and I somehow solved it without really understanding what I did. Today I wanted to set up my environment on a different computer and guess what, I had the same problem again. And I forgot what I had to do... This time however, I solved the problem more systematically and now I understand every step.

几个月前,我已经遇到了同样的问题,我以某种方式解决了它,但并没有真正理解我做了什么。今天我想在另一台计算机上设置我的环境,猜猜怎么着,我又遇到了同样的问题。我忘记了我必须做什么......然而这一次,我更系统地解决了问题,现在我明白了每一步。

The Solution - every step in detail

解决方案 - 每一步的细节

1)If you are importing someone else's project, make sure to have the correct JDK and JRE installed and selected in Eclipse. My Eclipse had selected the latest JRE 7. The only one I had installed. But the Project that I work on requires JDK 6 and JRE 6. I recommend the following structure on your file system if you need to have multiple java versions

1)如果是导入别人的项目,请确保在Eclipse中安装并选择了正确的JDK和JRE。我的 Eclipse 选择了最新的 JRE 7。我安装的唯一一个。但是我从事的项目需要 JDK 6 和 JRE 6。如果您需要多个 java 版本,我建议您的文件系统采用以下结构

  • somePath/Java/JDK/JDK6/
  • somePath/Java/JDK/JDK7/
  • somePath/Java/JRE/JRE6/
  • somePath/Java/JRE/JRE7/
  • somePath/Java/Java3D/
  • somePath/Java/JDK/JDK6/
  • somePath/Java/JDK/JDK7/
  • somePath/Java/JRE/JRE6/
  • somePath/Java/JRE/JRE7/
  • somePath/Java/Java3D/

2)In Eclipse, you will have to do the following steps to select the correct JDK and JRE.

2)Eclipse 中,您必须执行以下步骤来选择正确的 JDK 和 JRE

  • Project > Properties > Java Compiler, check "Enable project specific settings", then select the correct Compiler compliance levelfor your project. In my case it's 1.6for the use with JDK6. (The naming was really confusing for me, at least the 6 was a hint.)
  • You also have to make sure that the correct JREis used when you run the application. Therefore open Run>Run Configurationsand select the tab JRE. If you use JDK 6, then you have to make sure that JRE 6 is used. You can add JREs if you click onto "Installed JREs" and then add the somePath/Java/JRE/JRE6/directory.
  • Project > Properties > Java Compiler,选中“Enable project specific settings”,然后为您的项目选择正确的编译器合规性级别。在我的情况下,它是1.6用于JDK6。(命名对我来说真的很混乱,至少 6 是一个提示。)
  • 您还必须确保在运行应用程序时使用了正确的JRE。因此,打开Run>Run Configurations并选择选项卡 JRE。如果您使用 JDK 6,那么您必须确保使用 JRE 6。如果单击“已安装的 JRE”,然后添加somePath/Java/JRE/JRE6/目录,则可以添加JRE

3)Having your Java environment set up correctly, make sure that Java3Dis installed on your machine. You can't do anything wrong with this.

3)正确设置 Java 环境后,确保在您的机器上安装了Java3D。你不能做错任何事。

4)In your Java3D installation directory, locate the files

4)在您的 Java3D 安装目录中,找到文件

  • j3dcore-ogl.dll(for Windows; on Linux it's j3dcore-ogl.so)
  • j3dcore.jar
  • j3dutils.jar
  • vecmath.jar
  • j3dcore-ogl.dll(对于 Windows;在 Linux 上是 j3dcore-ogl.so)
  • j3dcore.jar
  • j3dutils.jar
  • vecmath.jar

It doesn't matter where these files are located if you setup your environment correctly, which I will explain. So if you want, you can copy these files into your project directory to have everything you need in one place.

如果您正确设置了环境,这些文件位于何处并不重要,我将对此进行解释。因此,如果您愿意,您可以将这些文件复制到您的项目目录中,以便将您需要的所有内容集中在一处。

5)Having located these files, make sure that

5)找到这些文件后,请确保

  • On your Operating System, the location of j3dcore-ogl.dllis added to the PATHvariable. The .dll or .so file contains machine native code that Java3D uses. Your system needs to be aware of this code's existence. Under Windows, to set the PATH variable, you open the System Settings in your Control Panel and select Advanced System Settings. On the bottom you will find the button "Environment Variables". In the System Variables list you will find the variable "Path". Make sure the directory of j3dcore-ogl is included in the list of paths.
  • Back in Eclipse, wherever the *.jar files currently are, make sure they are included in your Project>Properties>Java Build Path>Libraries. You can add them by either using Add JARsor Add External JARs, depending on whether you copied the three JARs to the project directory or not.
  • 在您的操作系统上,j3dcore-ogl.dll的位置被添加到PATH变量中。.dll 或 .so 文件包含 Java3D 使用的机器本机代码。您的系统需要知道此代码的存在。在 Windows 下,要设置 PATH 变量,请在控制面板中打开系统设置并选择高级系统设置。在底部,您会找到“环境变量”按钮。在系统变量列表中,您将找到变量“路径”。确保路径列表中包含 j3dcore-ogl 的目录。
  • 回到 Eclipse,无论 *.jar 文件当前在哪里,请确保它们包含在您的Project>Properties>Java Build Path>Libraries 中。您可以使用Add JARsAdd External JARs添加它们,具体取决于您是否将三个 JAR 复制到项目目录中。

6)Now comes the part that saved my day today.

6)现在是今天拯救我一天的部分。

For each of the Java3D Libraries listed in the Java Build Path

对于 Java 构建路径中列出的每个 Java3D 库

  • j3dcore.jar
  • j3dutils.jar
  • vecmath.jar,
  • j3dcore.jar
  • j3dutils.jar
  • vecmath.jar,

you need to specify Native Library Location. The Native library is the j3dcore-ogl.dll, so edit the native library location to point to the directory containing j3dcore-ogl.dll.

您需要指定Native Library Location。本机库是j3dcore-ogl.dll,因此编辑本机库位置以指向包含 j3dcore-ogl.dll 的目录。

I believe, that these are all steps that must be done to setup Java3D in eclipse, because I set up everything on a fresh computer today. Now I hope that these instructions will save some other poor Java-beginners', students' or programmers' day :-)

我相信,这些都是在 eclipse 中设置 Java3D 必须完成的所有步骤,因为我今天在一台新计算机上设置了所有内容。现在我希望这些说明能拯救其他一些可怜的 Java 初学者、学生或程序员的一天:-)

回答by Sorand

Just try to this code, it's help me:

试试这个代码,它对我有帮助:

  GraphicsConfiguration config =
       SimpleUniverse.getPreferredConfiguration();

    Canvas3D canvas3D = new Canvas3D(config);

回答by user3260860

I had the same problem. Solved it setting the Native path:

我有同样的问题。解决了它设置本机路径:

Properties - java build path - libraties - java3Dlib - Native library location - External folder -----> find the path: ....Java/Java3D/1.5.1/bin or the path where is the file: j3dcore-ogl.dll

属性 - java 构建路径 - libraties - java3Dlib - 本机库位置 - 外部文件夹 -----> 找到路径:....Java/Java3D/1.5.1/bin 或文件所在的路径:j3dcore-ogl .dll

回答by Micha? ?bikowski

As an addendum to given answers, what helped me set java 3d was: Copy and paste all the .dll files from "C:\Program Files\Java\Java3D\1.5.X\bin\" to "C:\Program Files\Java\jre6\bin\". So form Java3D to my actual jre6(from bin to bin).

作为给定答案的附录,帮助我设置 java 3d 的是:将所有 .dll 文件从“C:\Program Files\Java\Java3D\1.5.X\bin\”复制并粘贴到“C:\Program Files\ Java\jre6\bin\”。因此,将 Java3D 形成为我实际的 jre6(从 bin 到 bin)。

Previously I also set the classpath/(you can also set path) to 3dcore.jar, j3dutils.jar, vecmath.jar, j3dcore-ogl.dll but still did not work.

之前我也把classpath/(你也可以设置路径)设置为3dcore.jar, j3dutils.jar, vecmath.jar, j3dcore-ogl.dll 但还是不行。

After copy past j3dcore-ogl.dll (described above) and left classpath to 3dcore.jar, j3dutils.jar, vecmath.jar (in "C:\Program Files\Java\Java3D\1.5.X\ext\") it worked fine.

复制过去 j3dcore-ogl.dll(如上所述)并将类路径保留到 3dcore.jar、j3dutils.jar、vecmath.jar(在“C:\Program Files\Java\Java3D\1.5.X\ext\”中)后,它起作用了美好的。

I have found help here: http://www.xinapse.com/Manual/install_windows.htmlLook at the point 2.

我在这里找到了帮助:http: //www.xinapse.com/Manual/install_windows.html看第 2 点。

Best regards

此致

回答by gouessej

I know it's a very old question but some developers are still installing an obsolete version of Java 3D which is harder to use with or without an IDE. Please rather use Java 3D 1.6.0 and follow my detailed instructions (in English and in French) available here.

我知道这是一个非常古老的问题,但一些开发人员仍在安装 Java 3D 的过时版本,无论是否有 IDE,都很难使用。请宁可使用 Java 3D 1.6.0 并按照我在此处提供的详细说明(英语和法语)进行操作。

回答by user2081279

SOLVED - JonnyO answer is right.

已解决 - JonnyO 的回答是正确的。

I am using java 8 on linux, and downloaded from https://java3d.java.net/binary-builds.html(take the linux-amd64 version for an intel 64 bit system).

我在 linux 上使用 java 8,并从https://java3d.java.net/binary-builds.html下载(对于 intel 64 位系统采用 linux-amd64 版本)。

After unzipping the downloaded file, and then unzipping the contained j3d-jre.zip and adding the jar files to project and the libj3dcore-ogl.so to the jar, it still did not work. I had to add the libj3dcore-ogl.so to the library path. (Lazy as I am, I just copied it to /usr/lib, what is sufficient.)

将下载的文件解压后,再解压其中的j3d-jre.zip,将jar文件加入project,将libj3dcore-ogl.so加入jar,还是不行。我不得不将 libj3dcore-ogl.so 添加到库路径中。(虽然我很懒,我只是复制到/usr/lib,什么就够了。)

Now it is working.

现在它正在工作。

PS: Make sure to remove any other j3dcore.jar and j3dutils.jar beforehand.

PS:确保事先删除任何其他 j3dcore.jar 和 j3dutils.jar。

回答by Callahan O'C

I had this exact problem and the solution for me (I use eclipse) was to download the 32-bit (i586) (from https://java3d.java.net/binary-builds.html) archive and use those natives.

我遇到了这个确切的问题,我的解决方案(我使用 eclipse)是下载 32 位(i586)(来自https://java3d.java.net/binary-builds.html)存档并使用这些本地程序。