我有一个JavaFX项目,希望将其构建为Jar文件。然而,当我尝试这样做时,出现了错误。
Error:Java FX Packager: Can't build artifact - fx:deploy is not available in this JDK
我在这里发现了一个相似的问题,但是看起来他们没有得出结论。
我有一个JavaFX项目,希望将其构建为Jar文件。然而,当我尝试这样做时,出现了错误。
Error:Java FX Packager: Can't build artifact - fx:deploy is not available in this JDK
我在这里发现了一个相似的问题,但是看起来他们没有得出结论。
出现这种情况的原因可能是您安装了多个JDK,导致编译和运行使用不同的JDK版本,或者在Intellij中创建构件时使用了破损的Javafx应用程序jar功能。在执行以下步骤之前,请确保您正在使用相同的JDK版本进行编译和运行。
启动器类将调用主JavaFx类,从中运行您的应用程序。直接通过主类创建Jar文件会产生以下错误:
Error: Could not find or load main class Main
Caused by: java.lang.ClassNotFoundException: Main
你的启动器类应该看起来像这样:
public class Launcher {
public static void main(String[] args) {
MainGUI.main(args);
}
}
你可能仍然拥有上一次构建的META-INF
文件夹,所以请将其删除。
构建项目为JAR包:
文件->项目结构 -> 艺术品 -> "+" -> JAR->从具有依赖关系的模块中..
选择启动器类作为主类,并勾选“复制到输出目录并通过清单链接”,然后按下“确定”。
点击“应用”再点击“确定”。
转到“Build-> Build artifacts-> Rebuild”。
Error:Java FX Packager: Can't build artifact – fx:deploy is not available in this JDK
The
fx:deploy
task was a part of the Ant plugin that was formerly distributed inant-javafx.jar
as a part of Java Packager. The Ant plugin is not included in jpackage in the current JDK versions.If you're using a JDK build of version 9 and later, use third-party solutions for packaging. For example, refer to section Runtime images in the JavaFX official documentation.