简体   繁体   English

JavaFX 作为 MavenDependency - jar 从 Oracle JDK 开始,但不在 openJDK 上

[英]JavaFX as MavenDependency - jar starts on Oracle JDK but not on openJDK

I'm about to finish my master thesis.我即将完成我的硕士论文。 The program, i developed, is a maven project with javaFx declared as dependencies我开发的程序是一个 maven 项目,其中 javaFx 声明为依赖项

<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-fxml</artifactId>
    <version>16-ea+4</version>
</dependency>

<dependency>
    <groupId>org.ow2.asm</groupId>
    <artifactId>asm-util</artifactId>
    <version>8.0.1</version>
</dependency>

 <dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-base</artifactId>
    <version>16-ea+4</version>
</dependency>

<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>16-ea+4</version>
</dependency>   

When I'm creating the jar using Maven-install the program runs on Oracle-JDK.当我使用 Maven-install 创建 jar 时,程序在 Oracle-JDK 上运行。 But on openJDK it throws a java.lang.ClassNotFoundException.但在 openJDK 上,它会抛出 java.lang.ClassNotFoundException。

My understanding is, that javaFX is not included in both JDKs anymore.我的理解是,javaFX 不再包含在两个 JDK 中。 Thats why I'm unsing maven and build the jar with all dependencies.这就是为什么我要取消 maven 并构建具有所有依赖项的 jar 的原因。 That way it should find javaFx and start the program regardless the used JDK.这样它应该找到 javaFx 并启动程序,而不管使用的 JDK。

Assuming my assumption is correct that the error has something to do with javaFX.假设我的假设是正确的,该错误与 javaFX 有关。

To compile the Program I'm using JavaSE 13. It runs perfectly using Oracle JDK 15. But it throws a java.lang.ClassNotFoundException using openJDK 14 or 15.为了编译我使用 JavaSE 13 的程序。它使用 Oracle JDK 15 完美运行。但它使用 openJDK 14 或 15 抛出 java.lang.ClassNotFoundException。

---EDIT--- - -编辑 - -

I'm not totaly sure if this error is regarded to JavaFX.我不确定此错误是否与 JavaFX 相关。

I'm starting the jar on the console with我正在控制台上启动 jar

java -jar "C:...\test.jar"

This works on the OracleJDK but not on the openJDK.这适用于 OracleJDK,但不适用于 openJDK。 Then the Console prinst:然后控制台打印:

Error: Could not find or load main class C:\...\test 
Caused by: java.lang.ClassNotFoundException: C:\...\test

I know how to print the stacktrace, using the IDE.我知道如何使用 IDE 打印堆栈跟踪。 But is it possible to print the stacktrace using the console in this case?但是在这种情况下是否可以使用控制台打印堆栈跟踪?

If so I will do it an edit this question to provide more info.如果是这样,我会编辑这个问题以提供更多信息。

I would be so grateful for your help.我会很感激你的帮助。 I panic ^^我慌了^^

You are only providing us with some fragments of your setup.您只是向我们提供了您设置的一些片段。 So it is difficult to give any specific advice.所以很难给出具体的建议。 From what I see I'd say that your program cannot work on any Java which does not contain JavaFX because you do not provide the required arguments in your launch command.据我所知,我会说您的程序无法在任何不包含 JavaFX 的 Java 上运行,因为您没有在启动命令中提供所需的 arguments。 Have a look here for proven ways to launch JavaFX correctly: https://openjfx.io/openjfx-docs/在这里查看正确启动 JavaFX 的行之有效的方法: https://openjfx.io/openjfx-docs/

Do you have a MANIFEST.MF file?你有 MANIFEST.MF 文件吗? IT should point towards the class that has your public static void main(String[] args) method <-- Your main method.它应该指向具有公共 static void main(String[] args) 方法<--您的主要方法的 class。

Example:例子:

MANIFEST.MF

Manifest-Version: 1.0
Main-Class: classes.TestClass

Helpful stackoverflow: Could not find or load main class with a Jar File有用的stackoverflow: 无法使用Jar文件找到或加载主class

https://taylorial.com/cs1021/Jar.htm#jarwithjavafxpackagesincluded https://taylorial.com/cs1021/Jar.htm#jarwithjavafxpackagesincluded

my Prof just responded and says that it was just a typo in his commandline.我的教授刚刚回复说这只是他的命令行中的一个错字。

It works perfectly fine.它工作得很好。

I will delete this question in view hours, cause it is not really a problem.我会在查看时间删除这个问题,因为它不是一个真正的问题。

Thank you very much.非常感谢。

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

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