【发布时间】:2019-11-19 14:52:49
【问题描述】:
我的问题是我无法导出我的 JavaFX 应用程序。我可以使用 VM 参数(在 IDE 内部和外部)运行它,但这远非最佳。我想要一个简单的“点击打开”体验。
错误:JavaFX 运行时组件丢失,是运行此应用程序所必需的
我知道这个问题可以通过 vm 参数解决,但正如我之前所说的“点击打开”体验。
我尝试使用 maven 制作一个胖罐子。 (这是我的 pom.xml):
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Test</groupId>
<artifactId>Test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>11</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>make-jar-with-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>test.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我仍然遇到同样的错误,但导出过程比平时花费了更长的时间,可能是因为 JavaFX 组件也被导出了。 我认为值得一提的是,我在 pom.xml 中收到了警告
覆盖 maven-assembly-plugin pom.xml 的托管版本 2.2-beta-5
这是我的 module-info.java(也许它有助于解决问题):
module Test {
requires transitive javafx.controls;
exports test;
}
【问题讨论】:
-
有了新的java模块系统,这将是非常困难的。 Oracle / OpenJDK 提出的最好的方法是启动脚本 -
*.bat或*.sh文件。应该可以使用 maven-shade-plugin 和 jlink 创建一个包含所有类的着色 jar,以创建一个包含所需 JavaFX 模块的自定义 JRE。我还设法使用launch4j-maven-plugin 创建了一个launch4j 可执行文件。有很多方法可以获得点击打开体验。这取决于您真正想要什么,以及您想要运送到的方式和目的地。 -
这真是令人沮丧,他们为什么会想出这个……还是谢谢你!
-
您是否在任何给定平台(例如 Windows)上?
-
不,不是。
-
我认为您缺少 javafx-graphics 依赖项。对于 Windows,例如:
<dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-graphics</artifactId> <version>11</version> <classifier>win</classifier> </dependency>