如何在Eclipse中使用JavaFX 11? [英] How do I use JavaFX 11 in Eclipse?

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

问题描述

我在使用JavaFX时遇到了一些麻烦.我想开始至少创建一些桌面或移动应用程序.因此,我发现可以使用JavaFX库.但是据我所知,它已从JDK 9中排除.我实际上是在Ubuntu 18上使用OpenJDK 11(尽管Eclipse写道我有JavaSE 10环境,这也是我有点困惑的地方),并且我安装了OpenJFX使用sudo apt install openjfx,我无法使Eclipse与JavaFX一起使用.

I have some trouble with JavaFX. I wanted to start creating apps, desktop or mobile, at least something. So I found out I could use the JavaFX library for it. But as far as I understood, it was excluded from JDK 9. I'm actually using OpenJDK 11 on Ubuntu 18 (though Eclipse writes I have the JavaSE 10 environment, that is where I'm also a bit confused) and I installed OpenJFX using sudo apt install openjfx and I can't make Eclipse work with JavaFX.

我不确定是否有理由不将JDK 8与随附的JavaFX一起使用,但是无论如何,如何在Eclipse中的这种情况下使用JavaFX?

I'm not sure if there's any sense not to use JDK 8 with the included JavaFX, but anyway, how can I use JavaFX in such conditions in Eclipse?

推荐答案

您的帖子中有很多需要澄清的地方.我将尝试在不同的要点回答它们:

There are multiple points in your post which needs clarification. I will try to answer them in different bullet points:

但是据我了解,它(JavaFX)被排除在JDK 9中.

But as far as I understood, it(JavaFX) was excluded from JDK 9.

从开始JDK 11开始,JavaFX将与 Oracle JDK 脱钩.我强调Oracle JDK,因为JavaFX从来都不是OpenJDK的一部分.甚至在OpenJDK 8中也没有.

JavaFX will be decoupled from Oracle JDK starting JDK 11. I stress on Oracle JDK because JavaFX was never a part of OpenJDK. Not even in OpenJDK 8.

我实际上是在Ubuntu 18上使用OpenJDK 11(尽管eclipse写道我有JavaSE 10环境,这也是我有点困惑的地方)

I'm actually using OpenJDK 11 on Ubuntu 18 (Though eclipse writes I have JavaSE 10 environment, that is where I'm also a bit confused)

对于Eclipse中的Java 11支持,您需要安装 Java 11支持Eclipse Photon 插件.

For Java 11 support in Eclipse, you need to install Java 11 Support for Eclipse Photon plugin.

这里有一些如何在Eclipse中运行Java 11应用程序的示例

我使用sudo apt install openjfx安装了openjfx,但无法使eclipse与JavaFX一起使用.

I installed openjfx using sudo apt install openjfx and I can't make eclipse work with JavaFX.

我不确定是否有理由不将JDK 8与随附的JavaFX一起使用,但是无论如何,在这种情况下如何在Eclipse中使用JavaFX?

I'm not sure if there's any sense not to use JDK 8 with included JavaFX, but anyway, how can I use JavaFX in such conditions in eclipse?

由于OpenJDK 11或Oracle JDK 11不会与JavaFX捆绑在一起,所以最好的选择是从此处并将其加载到您的IDE中.

Since OpenJDK 11 or Oracle JDK 11 will not come bundled with JavaFX, your best bet is to either download the JavaFX SDK from here or here and load them in your IDE.

如果您习惯于构建工具,则可以直接使用

If you are used to build tools, you can directly use the JavaFX runtime jars which are available in Maven Central.

有关如何在OpenJDK 11上运行JavaFX 11的教程,请遵循:

For a tutorial on how to run JavaFX 11 on OpenJDK 11, you can follow:

  • Getting Started with JavaFX 11
  • JavaFX on JDK 11

撰写本文时,您需要 Eclipse 4.9 M3 与JavaFX 11配合使用.

At the time of writing this post, you need Eclipse 4.9M3 to work with JavaFX 11.

一旦有了Eclipse,JDK 11和JavaFX 11 SDK,您就可以选择创建:

Once you have eclipse, JDK 11 and JavaFX 11 SDK, you can either opt to create:

  • 基于模块的项目
  • 基于非模块的项目(无需module-info.java)

基于模块的项目

创建一个Java项目,并将Java FX 11 SDK中的JavaFX jar添加到项目的模块路径.

Create a Java project and add JavaFX jars from the Java FX 11 SDK to the module path of the project.

创建一个module.info并声明其对javafx.controls模块的依赖关系. javafx11是包含Java文件的软件包的名称.

Create a module.info and declare its dependency of javafx.controls module. javafx11 is the name of the package which contains your Java file.

module javafx11 {
    requires javafx.controls;
    exports javafx11;
}

运行程序\ o/

基于非模块的项目

创建一个Java项目,并将Java FX 11 SDK中的JavaFX jar添加到 项目的模块路径或类路径.

Create a Java project and add JavaFX jars from the Java FX 11 SDK to either the module-path or classpath of the project.

将以下JVM args添加到项目的运行配置中:

Add the following JVM args to the run configuration of the project:

--module-path=path-to-javafx-skd/lib --add-modules=javafx.controls

运行程序\ o/

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

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