如何使用JDK 11/Maven/Eclipse IDE运行JavaFX应用程序 [英] How to run JavaFX application using JDK 11/Maven/Eclipse IDE

查看:184
本文介绍了如何使用JDK 11/Maven/Eclipse IDE运行JavaFX应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:从Eclipse IDE运行基于Maven非模块项目(项目名称="howdyjfx")的JavaFX应用程序会产生以下编译错误:

The problem: Running a JavaFX application that is based on a Maven non-module project (project name = "howdyjfx") from the Eclipse IDE generates the following compilation error:

[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的摘录:
  • OS: Windows 10
  • IDE: Eclipse 2019-03 (4.11.0)
  • Installed JDK: jdk-11.0.3, this is the default (and only) JDK installed in the workspace. The project build path is Java SE-11 (jdk-11.0.3). Because Eclipse requires a Java 1.8 JRE, jdk1.8.0_211 is also installed on my computer; Eclipse will not run without this.
  • Builder: All projects are non-modular and compiled using Maven. Eclipse handles this with its built-in m2e feature.
  • Pom: Here's an extract from the 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();
         }
    }

以上配置和代码基于入门指南" 高级.Jose Pereda的Github帖子,以及

The above configuration and code is based on the 'Getting Started' guide and Sr. Jose Pereda's Github post, and also on the answer to a similar question that was asked last September. For whatever reason, however, I can't get this to work. This is all the more frustrating because I'm finishing an extensive library of JFX controls that compile without any problems (using both JDK 11 and JavaFX 11) and work fine in Scene Builder (apart from some Scene Builder issues that aren't relevant here).

在此先感谢您提供任何有用的建议!

Thanks in advance for any useful suggestions!

推荐答案

pom 文件中的配置正确,但是< configuration> < javafx-maven-plugin 的/code>部分错误.在入门"指南和Github存储库中的资料中, mainClass 的名称为'org.openjfx.hellofx.App ,这是一个组合< groupId> 加上< artifactId> 加上简单类名.因为我项目的< groupId> < artifactId> com.spindotta.jfx11.testbed howdyjfx 简单类名HowdyJFX 组合在一起.这是不正确的,因为该项目具有标准的Maven配置 source/main/java 以及顶级文件夹 howdyjfx .在插件中将 howdyjfx/HowdyJFX 指定为 mainClass 即可解决此问题.

The configuration in the pom file is correct, but the specification for the main class in the <configuration> section of the javafx-maven-plugin is wrong. In the both the ‘Getting started’ guide and the material on the Github repo, the name for the mainClass is ‘ org.openjfx.hellofx.App, which is a combination of the <groupId> plus <artifactId> plus the simple class name. Because the <groupId> and <artifactId> for my project are com.spindotta.jfx11.testbed and howdyjfx, respectively, I combined them with the simple class name HowdyJFX. This was incorrect because the project has the standard Maven configuration source/main/java plus a top-level folder howdyjfx. Specifying howdyjfx/HowdyJFX as the mainClass in the plugin fixed the problem.

对于价值而言,在 javafx-maven-plugin < configuration> 中指定的项目是必不可少的;省略任何内容都会产生 ERROR .应该可以在 Run配置->中指定这些值.JRE标签->VM参数,尽管我发现使用模板在 pom 中更容易处理.

For what it’s worth, the items specified in the <configuration> for the javafx-maven-plugin are essential; omitting any will generate an ERROR. It should be possible to specify these values in the Run configurations -> JRE tab -> VM arguments, although I find it easier to handle this in the pom using a template.

感谢Jose Pereda阐明了必须在运行配置中为启动指定的 Goals 问题.

Thanks to Jose Pereda for clarifying an issue with the Goals that must be specified in the Run configurations for the launch.

现在还有另一个问题.我需要能够调试入门指南中建议的方法启动的JavaFX应用程序.和 Github存储库.我在主类HowdyJFX 的第一行中设置了一个 Eclipse 断点,该行已分配了变量,这样应用程序将在该位置停止,这不会发生.而是运行应用程序,好像断点不在那里.这是与当前问题不同的问题,并且会在

Now there is another problem. I need to be able to debug JavaFX applications that are launched by the method suggested in the Getting Started guide and the Github repo. I set an Eclipse breakpoint in the main class HowdyJFX at the first line where a variable is assigned, so that the application would stop at that point, which did not happen. Instead the application ran as if the breakpoint wasn’t there. This is a different issue than the one at hand and is raised elsewhere.

这篇关于如何使用JDK 11/Maven/Eclipse IDE运行JavaFX应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆