如何使用JDK 11/Maven/EclipseIDE运行JavaFX应用程序

如何使用JDK 11/Maven/EclipseIDE运行JavaFX应用程序,eclipse,maven,javafx,Eclipse,Maven,Javafx,问题:从Eclipse IDE运行基于Maven非模块项目(project name=“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-ma

问题:从Eclipse IDE运行基于Maven非模块项目(project name=“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 安装在工作区中。项目构建路径是JavaSE-11 (jdk-11.0.3)。因为Eclipse需要Java1.8JRE,所以jdk1.8.0Ó 也安装在我的电脑上;没有这个,Eclipse将无法运行
  • Builder:所有项目都是非模块化的,使用Maven编译。 Eclipse通过其内置的m2e特性来处理这个问题
  • Pom:以下是Pom的摘录:
上述配置和代码基于and,也基于去年9月询问的a的答案。不管出于什么原因,我都不能让它工作。这更令人沮丧,因为我正在完成一个广泛的JFX控件库,这些控件可以毫无问题地编译(使用JDK 11和JavaFX 11),并且在场景生成器中工作良好(除了一些与此处无关的场景生成器问题)


提前感谢您提供的有用建议

pom
文件中的配置是正确的,但是
javafx maven插件的
部分中的主类规范是错误的。 在《入门指南》和Github repo上的资料中,
mainClass
的名称是
'org.openjfx.hellofx.App
,它是
的组合。我在
main类HowdyJFX
的第一行变量赋值处设置了一个
Eclipse
断点,这样应用程序就会在该点停止,而这并没有发生。相反,应用程序的运行就像断点不在那里一样。
这是一个与当前问题不同的问题,并且被提出。

pom
文件中的配置是正确的,但是
javafx maven插件的
部分中的主类规范是错误的。 在《入门指南》和Github repo上的资料中,
mainClass
的名称是
'org.openjfx.hellofx.App
,它是
的组合。我在
main类HowdyJFX
的第一行变量赋值处设置了一个
Eclipse
断点,这样应用程序就会在该点停止,而这并没有发生。相反,应用程序的运行就像断点不在那里一样。
这是一个与当前问题不同的问题,并且被提出。

看起来您正在运行Eclipse的默认目标,它可能使用默认的Maven插件。您需要编辑配置并添加
mvn clean javafx:run
,如您链接的指南所述。还要注意的是,样本回购协议不是我的。@JoséPereda对混乱表示抱歉,感谢您的耐心,我与编辑有问题;以下是完整的注释(分为尺寸限制的三部分b/c)。如果运行配置->主选项卡->目标指定(i)
clean exec:java
或(ii)
clean exec:java javafx:Run
,这将为我的问题中的错误消息中描述的“mainClass”生成缺少/无效的参数@JoséPereda如果将“目标”更改为(i)
clean javafx:run
或(ii)
clean javafx:run exec:java
,则会出现不同的错误消息结果:
无法执行目标组织。openjfx:javafx maven插件:0.0.2:run(默认cli)on project howdyjfx:error:命令执行失败。进程退出时出现错误:1(退出值:1)
。运行配置->JRE选项卡->“VM参数”为空。这里应该有什么吗?另外,
pom
中的
javafxmaven插件的
设置是否正确?(只有两部分,这是第二部分)。您不需要同时使用
exec:java
javafx:run
。运行项目只需要一个插件
javafx:run
是您所需要的。如果您有其他问题,那么您必须找到这些问题并尝试解决它们。使用新配置和问题编辑您的问题。尽管评论无法解决这些问题。@JoséPereda谢谢你的帮助,我自己回答了这个问题。值得一提的是,与JavaFX11之前的版本相比,现在启动应用程序的过程是一场噩梦,肯定不是前进的一步,这并不是你或OpenFX的反映。在“旧”方式下,您只需正确配置主类,然后单击“运行”(或“调试”)选项即可。对于那些正在考虑迁移到JavaFX或扩展该领域的开发人员来说,无论是谁做出重大决策,都需要记住这一点。再次感谢你的帮助!看起来您正在运行Eclipse的默认目标,它可能使用默认的Maven插件。您需要编辑配置并添加
mvn clean javafx:run
,如您链接的指南所述。还要注意的是,样本回购协议不是我的。@JoséPereda对混乱表示抱歉,感谢您的耐心,我与编辑有问题;以下是完整的注释(分为尺寸限制的三部分b/c)。如果运行配置->主选项卡->目标指定(i)
clean exec:java
或(ii)
clean exec:java javafx:Run
,这将为我的问题中的错误消息中描述的“mainClass”生成缺少/无效的参数@若泽·佩雷达如果将“目标”更改为(i)
clean javafx:run
或(ii)
clean javafx:run exec:java
,则会出现不同的错误消息结果:
无法执行目标
    <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();
         }
    }