[英]JavaFX 11 jar not executable java.lang.NoClassDefFoundError: javafx/application/Application
[英]Bundling JavaFX Library with Maven in executable JAR (for Java 11+)
我正在使用Java 8
和JavaFX
。 When I package my executable JAR
with maven
, the executable JAR
works fine using Java 8
. 但是,如果我使用例如Java 13
运行JAR
,则会收到以下错误:
Error: Could not find or load main class ApplicationLauncherClient
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application
这可能是由于JavaFX
自Java 11
以来不再与JRE
/ JDK
捆绑在一起造成的。
我的pom.xml
构建配置如下所示:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>ApplicationLauncherClient</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
My goal is to instruct maven
to build a JAR
which can run on any Java
version greater than or equal to 8 by including JavaFX
in the executable JAR
.
我没有按照这个答案中的说明成功(例如,将JavaFX
插件添加到我的pom.xml
)。 包括OpenJFX
作为依赖项也不起作用,我仍然收到同样的错误。
我像这样使用 javafx-maven-plugin 和 maven-shade-plugin:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>Your_main_class</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>Your_main_class_starter</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Your_main_class 是这样的:
public class App extends Application {
private static Scene scene;
@Override
public void start(Stage stage) throws IOException {
Parent mainForm = FXMLLoader.load(getClass().getResource("mainForm.fxml"));
scene = new Scene(mainForm , 425, 275);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
Your_main_class_starter 看起来像这样:
public class LaunchApp {
public static void main(String[] args) {
App.main(args);
}
所以 Your_main_class_starter 除了调用你的主 class 之外什么也没做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.