简体   繁体   English

从 .jar 运行应用程序时出现 Java 3d 错误

[英]Java 3d error when running application from .jar

Hello when i am running my application from Eclipse it runs perfectly but when i export it as a runnable jar, it doesn't run.您好,当我从 Eclipse 运行我的应用程序时,它运行得很好,但是当我将它导出为可运行的 jar 时,它无法运行。 When i try running it from cmd it gives me one of 2 errors the first errror is after i just export it with the "copy required libraries into a sub-folder":当我尝试从 cmd 运行它时,它给了我 2 个错误之一,第一个错误是在我使用“将所需的库复制到子文件夹中”导出它之后:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no j3dcore-ogl in java.library.path
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at javax.media.j3d.NativePipeline$1.run(NativePipeline.java:189)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.media.j3d.NativePipeline.loadLibrary(NativePipeline.java:180)
    at javax.media.j3d.NativePipeline.loadLibraries(NativePipeline.java:137)
    at javax.media.j3d.MasterControl.loadLibraries(MasterControl.java:948)
    at javax.media.j3d.VirtualUniverse.<clinit>(VirtualUniverse.java:280)
    at javax.media.j3d.Canvas3D.<clinit>(Canvas3D.java:3862)
    at Main.Game.<init>(Game.java:39)
    at Main.Main.main(Main.java:6)

when i change the sub-folder's name from IslandDomination_lib to just lib it gives me another error:当我将子文件夹的名称从 IslandDomination_lib 更改为 lib 时,它给了我另一个错误:

    Exception in thread "main" java.lang.NoClassDefFoundError: javax/media/j3d/Canvas3D
      at Main.Main.main(Main.java:6)
    Caused by: java.lang.ClassNotFoundException: javax.media.j3d.Canvas3D
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 1 more

I have tried running it several ways:我试过几种方式运行它:

1. 1.

java.exe -jar IslandDomination.jar

2. 2.

java.exe -cp "lib/j3dcore.jar;lib/j3dutils.jar;lib/vecmath.jar" -jar IslandDomination.jar

3. using another java program to run it for me: 3.使用另一个java程序为我运行它:

package main;
import java.io.File;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException,     InterruptedException{
    ProcessBuilder pb = new   ProcessBuilder(System.getProperty("java.home")+"\\bin\\java.exe", "-cp" , "\"lib/j3dcore.jar;lib/j3dutils.jar;lib/vecmath.jar\"" , "-jar" , "IslandDomination.jar");
    pb.directory(new File("./"));
    Process p = pb.start();
    p.waitFor();
  }
}

The internal structure of my jar consists of 4 folders:我的 jar 的内部结构由 4 个文件夹组成:

J3DBool
Main
Maths
META-INF

The folder with the required jars is in the same folder as the main jar包含所需 jar 的文件夹与主 jar 位于同一文件夹中

You use a completely obsolete version of Java3D, which is very difficult to bundle in any software as you have to set the Java library path somehow and you have to bundle both the Java libraries and the native libraries.您使用的是完全过时的 Java3D 版本,很难将其捆绑到任何软件中,因为您必须以某种方式设置 Java 库路径,并且必须同时捆绑 Java 库本机库。 Rather rebuild your project with Java3D 1.6.0 pre 12, it's a lot easier to use as this version relies on JOGL 2 which uses automatic native library loading and everything is packaged as JARs, there is no longer any need of modifying the library path, just take care of the classpath.而是使用 Java3D 1.6.0 pre 12 重建您的项目,它更容易使用,因为该版本依赖于使用自动本地库加载的 JOGL 2,并且所有内容都打包为 JAR,不再需要修改库路径,只需照顾好类路径。

Please follow my tutorial , especially the very last section with (a lot) more information.请按照我的教程,尤其是最后一节提供(很多)更多信息。

Finally, the obsolete version that you use isn't guaranteed to work on any recent operating systems.最后,不能保证您使用的过时版本可以在任何最新的操作系统上运行。 If it works, you'll be lucky;如果它有效,你会很幸运; if it doesn't, nobody will fix it.如果没有,没有人会修复它。

I think the required library file (jar file) not found in the classpath.我认为在类路径中找不到所需的库文件(jar 文件)。

you need to set Library file in your class path.您需要在类路径中设置库文件。

step to set class path:-设置类路径的步骤:-

MyComputer->Properties->Advanced system setting->Environment variables我的电脑->属性->高级系统设置->环境变量

find "classpath" either in user variables area or in system variables if found edit that and put all the jar file link.如果找到,请在用户变量区域或系统变量中找到“类路径”,然后编辑并放置所有 jar 文件链接。 if not found then create new(click on new) and put all the jar link there and try to run your application如果未找到,则创建新的(单击新的)并将所有 jar 链接放在那里并尝试运行您的应用程序

我发现了如何解决我的问题,只需将所需的 dll 文件放在可执行 jar 文件旁边即可完成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM