如何在 Java 11 中将 JavaFX 运行时添加到 Eclipse? [英] How to add JavaFX runtime to Eclipse in Java 11?

查看:30
本文介绍了如何在 Java 11 中将 JavaFX 运行时添加到 Eclipse?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误,因为 Java 11 将 JavaFX 作为最新版本的一部分排除在外.

<块引用>

错误:JavaFX 运行时组件缺失,需要运行这个应用程序

那么如何在 Java 11 中将 JavaFX 添加到 Eclipse?谢谢.

解决方案

遵循入门指南,这些是从 Eclipse 运行 JavaFX 11 所需的步骤.

  1. 此处.

  2. 此处安装 JDK 11.

  3. 将 Java 11 作为已安装的 JRE 添加到 Eclipse:Eclipse ->窗口 ->首选项 ->Java ->已安装的 JRE ->添加.

  4. 此处下载 JavaFX 11 ea.

  5. 创建用户库:Eclipse ->窗口 ->首选项 ->Java ->构建路径 ->用户库 ->新的.将其命名为 JavaFX11,并在 JavaFX 11-ea 的 lib 文件夹下包含 jar.

  6. 创建一个 Java 项目.您不需要添加模块路径类.确保选择 Java 11 并将 JavaFX11 库添加到项目的模块路径中.

  7. 添加包javafx11和主应用类HelloFX:

 包 javafx11;导入 javafx.application.Application;导入 javafx.scene.Scene;导入 javafx.scene.control.Label;导入 javafx.scene.layout.StackPane;导入 javafx.stage.Stage;公共类 HelloFX 扩展应用程序 {@覆盖公共无效开始(阶段阶段){String version = System.getProperty(java.version");标签 l = 新标签(你好,JavaFX 11,运行于+版本");场景场景 = 新场景 (new StackPane(l), 300, 200);stage.setScene(场景);舞台表演();}公共静态无效主(字符串 [] args){发射();}}

请注意,编辑器不应抱怨 JavaFX 类,因为我们已经包含了用户库.

  1. 添加运行时参数.编辑项目的运行配置,并添加这些 VM 参数:

    --module-path C:UsersDownloadsjavafx-sdk-11lib --add-modules=javafx.controls

  2. 最后,运行项目.它应该可以正常工作.

I am getting the following error as Java 11 excluded the JavaFX as part of the latest version.

Error: JavaFX runtime components are missing, and are required to run
this application

So how can I add JavaFX to Eclipse in Java 11? Thanks.

解决方案

Following the getting started guide, these are the required steps to run JavaFX 11 from Eclipse.

  1. Install Eclipse 2018-09 from here.

  2. Install JDK 11 from here.

  3. Add Java 11 as an installed JRE to Eclipse: Eclipse -> Window -> Preferences -> Java -> Installed JREs -> Add.

  4. Download JavaFX 11 ea from here.

  5. Create a User Library: Eclipse -> Window -> Preferences -> Java -> Build Path -> User Libraries -> New. Name it JavaFX11 and include the jars under the lib folder from JavaFX 11-ea.

  6. Create a Java project. You don't need to add a module-path class. Make sure that you select Java 11 and you add the JavaFX11 library to the project's modulepath.

  7. Add a package javafx11 and the main application class HelloFX:

    package javafx11;
    
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    
    
    public class HelloFX extends Application {
    
        @Override
        public void start(Stage stage) {
            String version = System.getProperty("java.version");
            Label l = new Label ("Hello, JavaFX 11, running on "+version);
            Scene scene = new Scene (new StackPane(l), 300, 200);
            stage.setScene(scene);
            stage.show();
        }
    
        public static void main(String[] args) {
            launch();
        }
    
    }

Note that the editor shouldn't complain about JavaFX classes, as we have included the user library.

  1. Add runtime arguments. Edit the project's run configuration, and add these VM arguments:

    --module-path C:Users<user>Downloadsjavafx-sdk-11lib --add-modules=javafx.controls

  2. Finally, run the project. It should work fine.

这篇关于如何在 Java 11 中将 JavaFX 运行时添加到 Eclipse?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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