如何在java 11上将javaFx运行时添加到eclipse? [英] How to add javaFx runtime to eclipse on java 11?

查看:864
本文介绍了如何在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


谢谢

推荐答案

关注入门指南,这些是从Eclipse运行JavaFX 11所需的步骤。

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

1安装Eclipse 2018-09来自此处

1 Install Eclipse 2018-09 from here.

2从这里安装JDK 11

3将Java 11作为已安装的JRE添加到Eclipse:Eclipse - > Window - > Preferences - > Java - > Installed JREs - > Add。

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

4从这里

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

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天全站免登陆