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

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

问题描述

由于Java 11排除了JavaFX作为最新版本的一部分,因此出现以下错误.

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

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

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

推荐答案

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

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

1从这里.

2从此处安装JDK 11.

2 Install JDK 11 from here.

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

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

4从此处下载JavaFX 11.

4 Download JavaFX 11 ea from here.

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

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创建一个Java项目.您不需要添加模块路径类.确保选择Java 11,然后将JavaFX11库添加到项目的模块路径.

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添加一个程序包javafx11和主应用程序类HelloFX:

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();
    }

}

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

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

8添加运行时参数.编辑项目的运行配置,并添加以下VM参数:

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

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

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

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

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

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