eclipse - 如何使用 JDK 11/Maven/Eclipse IDE 运行 JavaFX 应用程序
问题描述
问题:从 Eclipse IDE 运行基于 Maven 非模块项目(项目名称 =“howdyjfx”)的 JavaFX 应用程序会生成以下编译错误:
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project howdyjfx: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java are missing or invalid.
开发环境及配置:
- 操作系统:Windows 10
- IDE:Eclipse 2019-03 (4.11.0)
- 已安装 JDK:jdk-11.0.3,这是工作区中安装的默认(也是唯一)JDK。项目构建路径为 Java SE-11 (jdk-11.0.3)。因为Eclipse需要Java 1.8 JRE,所以我的电脑上也安装了jdk1.8.0_211;没有这个,Eclipse 将无法运行。
- Builder:所有项目都是非模块化的,并使用 Maven 编译。Eclipse 使用其内置的 m2e 特性来处理这个问题。
- Pom:这是 pom 的摘录:
<modelVersion>4.0.0</modelVersion>
<groupId>com.spindotta.jfx11.testbed</groupId>
<artifactId>howdyjfx</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-controls -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>13-ea+8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-fxml -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>13-ea+8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- http://maven.apache.org/plugins/maven-compiler-plugin/ -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.2</version>
<configuration>
<!-- Is this necessary? The 'Run' configuration goals are "clean exec:java" -->
<executable>C:\Program Files\Java\jdk-11.0.3\bin\java</executable>
<!-- Workaround to short-circuit jdk1.8 which is needed to run Eclipse
but is toxic for jdk11 and higher -->
<options>
<option>-Djava.library.path=C:\tmp</option>
</options>
<!-- Main class - is this correct? -->
<mainClass>com.spindotta.jfx11.testbed.howdyjfx.HowdyJFX</mainClass>
</configuration>
</plugin>
</plugins>
</build>
申请代码为:
public class HowdyJFX extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
final String javaVersion = System.getProperty("java.version");
final String javafxVersion = System.getProperty("javafx.version");
final Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
final Scene scene = new Scene(new StackPane(l), 640, 480);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch();
}
}
上述配置和代码基于“入门”指南和Sr. Jose Pereda 的 Github 帖子,以及对去年 9 月提出的类似问题的回答。但是,无论出于何种原因,我都无法使其正常工作。这更加令人沮丧,因为我正在完成一个广泛的 JFX 控件库,该库可以毫无问题地编译(使用 JDK 11 和 JavaFX 11)并且在 Scene Builder 中工作正常(除了一些与这里无关的 Scene Builder 问题)。
提前感谢您提供任何有用的建议!
解决方案
文件中的配置是正确的,但是部分pom
主类的规范是错误的。在“入门”指南和 Github repo 上的资料中, 的名称是,它是加号加. 因为我的项目的和分别是 和 ,所以我将它们与. 这是不正确的,因为该项目具有标准的 Maven 配置和一个顶级文件夹。在插件中指定为解决了问题。<configuration>
javafx-maven-plugin
mainClass
‘ org.openjfx.hellofx.App
<groupId>
<artifactId>
simple class name
<groupId>
<artifactId>
com.spindotta.jfx11.testbed
howdyjfx
simple class name HowdyJFX
source/main/java
howdyjfx
howdyjfx/HowdyJFX
mainClass
对于它的价值,<configuration>
for the中指定的项目javafx-maven-plugin
是必不可少的;省略 any 将生成一个ERROR
. 应该可以在 中指定这些值,尽管我发现使用模板Run configurations -> JRE tab -> VM arguments
更容易处理这些值。pom
感谢 Jose Pereda 澄清了发布时Goals
必须指定的问题Run configurations
。
现在还有另一个问题。我需要能够调试由入门指南和Github repo中建议的方法启动的 JavaFX 应用程序。我在分配变量的第一行中设置了一个Eclipse
断点main class HowdyJFX
,以便应用程序将在该点停止,但这并没有发生。相反,应用程序就像断点不存在一样运行。这是一个与当前不同的问题,并在其他地方提出。
推荐阅读
- python - 使用连续行作为 Y 轴的小提琴图
- algorithm - 更快的算法与更快的计算机
- c++ - 根据加载的图像调整 QGraphicsView 的大小并始终保持纵横比
- php - 使用 PHP 从新闻站点访问 XML 元素和命名空间(已编辑)
- android - nativescript - 提取 tns-android 时验证失败
- javascript - 需要哪些 javascript 包含文件才能使布局扩展在 cytoscape 中工作?
- python - 熊猫数据框在排序后未保存
- python - 从嵌套列表 Python 中删除重复项 - 错误
- android - Android Studio:如何在一个屏幕上同时显示 2 个活动?
- javascript - 如何使用 switch case 将包含字符串的 a 值放入数组中的正确对象中?