Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

huangapple go评论101阅读模式
英文:

Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

问题

在IntelliJ中将我的JavaFX应用程序构建为JavaFX应用程序,并在控制台中使用以下命令运行jar文件时:

java -jar RaspberryShell.jar

我收到了这个错误:

错误:找不到或加载主类de.Jan.Raspberry.Shell.Main
原因:java.lang.NoClassDefFoundError: javafx/application/Application

我还在artifact中设置了主类,这不应该是个问题,如果我直接在IntelliJ中运行它,代码可以正常运行。

有人有想法吗?

英文:

When I try to build my javafx application in intellij as a JavaFX Application and I run the jar in console with

> java -jar RaspberryShell.jar

I get this error:

Error: Could not find or load main class de.Jan.Raspberry.Shell.Main
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

I also set the main class in the artifact that shouldn't be a problem and the code runs fine if I run it direct in intellij.

Does anyone have ideas?

答案1

得分: 1

尝试将以下内容添加到路径中:

--module-path /usr/local/javafx-sdk-14.0.1/lib --add-modules javafx.controls,javafx.fxml

只需将 /usr/local/javafx-sdk-14.0.1/lib 更改为包含 JavaFX 的目录即可。lib 目录应包含一些 .jar 文件,包括 javafx.fxml.jar。

英文:

Try to add this to the path:

--module-path /usr/local/javafx-sdk-14.0.1/lib --add-modules javafx.controls,javafx.fxml

Just change /usr/local/javafx-sdk-14.0.1/lib to the directory which contain javafx. The lib directory should contain some .jar files, including javafx.fxml.jar

答案2

得分: 0

你的运行时Java不包含JavaFX。更换为一个包含JavaFX的版本。

英文:

Your runtime Java does not include JavaFX. Change to one who does.

答案3

得分: 0

当您运行它时,请单击下拉箭头 -> 运行配置 -> 参数,然后将以下内容粘贴到VM参数中:(用您自己的lib路径替换)
--module-path "C:\Program Files\FX\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml
点击应用并运行!

英文:

When you run it, click on the drop down arrow -> Run configurations -> Arguments
Then paste the following into VM arguments: (Replace with your own path for lib)
--module-path "C:\Program Files\FX\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml
Press apply and run!

答案4

得分: 0

这个错误是因为你的机器上可能安装了两个JDK,一个是较旧版本的,比如包含javafx/application/Application作为JDK的一部分的Java 8,另一个是较新版本的,不包含该部分。
解决方法:
卸载新的JDK版本,保持JDK 8。

英文:

This Error is because you may have two JDK installed on your machine an older version like Java 8 which contains a javafx/application/Application as part of the JDK and a higher which does not.
Solution:
Uninstall new JDK version and maintain JDK 8

huangapple
  • 本文由 发表于 2020年7月26日 03:51:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/63092901.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定