JavaFX 和 OpenJDK
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18547362/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaFX and OpenJDK
提问by mdriesen
I'm trying to decide whether I could switch to JavaFX for the user interface of my Java application. Most of my users would be using the Oracle JRE, which has JavaFX integrated these days. However, some are using OpenJDK (on linux). This(old) question suggests that OpenJDK deals very badly with JavaFX. According to thisquestion, the alternative OpenJFX will only be fully integrated into OpenJDK in version 9. So my question is twofold:
我正在尝试决定是否可以为 Java 应用程序的用户界面切换到 JavaFX。我的大多数用户都会使用 Oracle JRE,现在它集成了 JavaFX。但是,有些正在使用 OpenJDK(在 linux 上)。这个(旧)问题表明 OpenJDK 对 JavaFX 的处理非常糟糕。根据这个问题,替代的 OpenJFX 只会在版本 9 中完全集成到 OpenJDK 中。 所以我的问题是双重的:
- Is the JavaFX support in OpenJDK still so bad?
- If so, are there any Linux distributions that already offer an OpenJFX package so users wouldn't have to build it themselves?
- OpenJDK 中的 JavaFX 支持是否仍然如此糟糕?
- 如果是这样,是否有任何 Linux 发行版已经提供了 OpenJFX 包,这样用户就不必自己构建它?
采纳答案by jewelsea
JavaFX is part of OpenJDK
JavaFX 是 OpenJDK 的一部分
The JavaFX project itself is open sourceand is part of the OpenJDK project.
JavaFX 项目本身是开源的,是OpenJDK 项目的一部分。
Update Dec 2019
2019 年 12 月更新
For current information on how to use Open Source JavaFX, visit https://openjfx.io. This includes instructions on using JavaFX as a modular library accessed from an existing JDK (such as an Open JDK installation).
有关如何使用开源 JavaFX 的最新信息,请访问https://openjfx.io。这包括使用 JavaFX 作为从现有 JDK(例如Open JDK 安装)访问的模块化库的说明。
The open source code repository for JavaFX is at https://github.com/openjdk/jfx.
JavaFX 的开源代码库位于https://github.com/openjdk/jfx。
At the source location linked, you can find license files for open JavaFX (currently this licensematches the license for OpenJDK: GPL+classpath exception).
在链接的源位置,您可以找到开放 JavaFX 的许可证文件(目前该许可证与 OpenJDK 的许可证匹配:GPL+classpath 例外)。
The wiki for the project is located at: https://wiki.openjdk.java.net/display/OpenJFX/Main
该项目的 wiki 位于:https: //wiki.openjdk.java.net/display/OpenJFX/Main
If you want a quick start to using open JavaFX, the Belsoft Liberica JDKdistributions provide pre-built binaries of OpenJDK that (currently) include open JavaFX for a variety of platforms.
如果您想快速开始使用开放式 JavaFX,Belsoft Liberica JDK发行版提供了 OpenJDK 的预构建二进制文件,其中(当前)包括适用于各种平台的开放式 JavaFX。
For distribution as self-contained applications, Java 14, is scheduled to implement JEP 343: Packaging Tool, which "Supports native packaging formats to give end users a natural installation experience. These formats include msi and exe on Windows, pkg and dmg on macOS, and deb and rpm on Linux.", for deployment of OpenJFX based applications with native installers and no additional platform dependencies (such as a pre-installed JDK).
对于作为自包含应用程序的分发,Java 14 计划实施JEP 343:打包工具,该工具“支持本机打包格式,为最终用户提供自然的安装体验。这些格式包括 Windows 上的 msi 和 exe,macOS 上的 pkg 和 dmg ,以及 Linux 上的 deb 和 rpm。”,用于使用本机安装程序部署基于 OpenJFX 的应用程序,并且没有其他平台依赖项(例如预安装的 JDK)。
Older information which may become outdated over time
随着时间的推移可能会过时的旧信息
Building JavaFX from the OpenJDK repository
从 OpenJDK 存储库构建 JavaFX
You can build an open version of OpenJDK (including JavaFX)completely from source which has no dependencies on the Oracle JDK or closed source code.
您可以完全从源代码构建OpenJDK(包括 JavaFX)的开放版本,它不依赖于 Oracle JDK 或封闭源代码。
Update: Using a JavaFX distribution pre-built from OpenJDK sources
更新:使用从 OpenJDK 源预先构建的 JavaFX 发行版
As noted in comments to this question and in another answer, the Debian Linux distributions offer a JavaFX binary distibution based upon OpenJDK:
正如对此问题的评论和另一个答案中所述,Debian Linux 发行版提供了基于 OpenJDK 的 JavaFX 二进制发行版:
- https://packages.qa.debian.org/o/openjfx.html
Install via:
sudo apt-get install openjfx
- https://packages.qa.debian.org/o/openjfx.html
通过以下方式安装:
sudo apt-get install openjfx
(currently this only works for Java 8 as far as I know).
(据我所知,目前这只适用于 Java 8)。
Differences between Open JDK and Oracle JDK with respect to JavaFX
Open JDK 和 Oracle JDK 在 JavaFX 方面的差异
The following information was provided for Java 8. As of Java 9, VP6 encoding is deprecated for JavaFXand the Oracle WebStart/Browser embedded application deployment technology is also deprecated. So future versions of JavaFX, even if they are distributed by Oracle, will likely not include any technology which is not open source.
下面的信息为Java 8中提供从Java 9,VP6编码已被弃用为JavaFX和甲骨文Webstart的/浏览器嵌入应用程序部署技术也已过时。因此,JavaFX 的未来版本,即使它们是由 Oracle 分发的,也可能不会包含任何非开源技术。
Oracle JDK includes some software which is not usable from the OpenJDK. There are two main components which relate to JavaFX.
Oracle JDK 包含一些无法从 OpenJDK 使用的软件。有两个主要组件与 JavaFX 相关。
- The ON2 VP6 video codec, which is owned by Google and Google has not open sourced.
- The Oracle WebStart/Browser Embedded application deployment technology.
- ON2 VP6 视频编解码器归谷歌所有,谷歌尚未开源。
- Oracle WebStart/Browser Embedded 应用程序部署技术。
This means that an open version of JavaFX cannot play VP6 FLV files. This is not a big loss as it is difficult to find VP6 encoders or media encoded in VP6.
这意味着 JavaFX 的开放版本无法播放 VP6 FLV 文件。这不是一个很大的损失,因为很难找到 VP6 编码器或以 VP6 编码的媒体。
Other more common video formats, such as H.264 will playback fine with an open version of JavaFX (as long as you have the appropriate codecs pre-installed on the target machine).
其他更常见的视频格式,例如 H.264 可以在 JavaFX 的开放版本中正常播放(只要您在目标机器上预装了适当的编解码器)。
The lack of WebStart/Browser Embedded deployment technology is really something to do with OpenJDK itself rather than JavaFX specifically. This technology can be used to deploy non-JavaFX applications.
缺乏 WebStart/Browser Embedded 部署技术实际上与 OpenJDK 本身有关,而不是与 JavaFX 相关。该技术可用于部署非 JavaFX 应用程序。
It would be great if the OpenSource community developed a deployment technology for Java (and other software) which completely replaced WebStart and Browser Embedded deployment methods, allowing a nice light-weight, low impact user experience for application distribution. I believe there have been some projects started to serve such a goal, but they have not yet reached a high maturity and adoption level.
如果开源社区为 Java(和其他软件)开发一种部署技术,完全取代 WebStart 和浏览器嵌入式部署方法,为应用程序分发提供良好的轻量级、低影响的用户体验,那就太好了。我相信已经有一些项目开始为这样的目标服务,但它们还没有达到很高的成熟度和采用水平。
Personally, I feel that WebStart/Browser Embedded deployments are legacy technology and there are currently better ways to deploy many JavaFX applications (such as self-contained applications).
就我个人而言,我认为 WebStart/Browser Embedded 部署是遗留技术,目前有更好的方法来部署许多 JavaFX 应用程序(例如自包含应用程序)。
Update Dec, 2019:
2019 年 12 月更新:
An open source version of WebStart for JDK 11+ has been developed and is available at https://openwebstart.com.
已开发出适用于 JDK 11+ 的 WebStart 开源版本,可从https://openwebstart.com 获得。
Who needs to create Linux OpenJDK Distributions which include JavaFX
谁需要创建包含 JavaFX 的 Linux OpenJDK 发行版
It is up to the people which create packages for Linux distributions based upon OpenJDK (e.g. Redhat, Ubuntu etc) to create RPMs for the JDK and JRE that include JavaFX. Those software distributors, then need to place the generated packages in their standard distribution code repositories (e.g. fedora/red hat network yum repositories). Currently this is not being done, but I would be quite surprised if Java 8 Linux packages did not include JavaFX when Java 8 is released in March 2014.
由基于 OpenJDK(例如 Redhat、Ubuntu 等)为 Linux 发行版创建包的人员为包含 JavaFX 的 JDK 和 JRE 创建 RPM。那些软件发行商则需要将生成的包放置在他们的标准发行代码存储库中(例如,fedora/red hat 网络 yum 存储库)。目前这还没有完成,但如果 Java 8 Linux 包在 2014 年 3 月发布 Java 8 时不包含 JavaFX,我会感到非常惊讶。
Update, Dec 2019:
2019 年 12 月更新:
Now that JavaFX has been separated from most binary JDK and JRE distributions (including Oracle's distribution) and is, instead, available as either a stand-alone SDK, set of jmods or as a library dependencies available from the central Maven repository(as outlined as https://openjfx.io), there is less of a need for standard Linux OpenJDK distributions to include JavaFX.
现在 JavaFX 已经从大多数二进制 JDK 和 JRE 发行版(包括 Oracle 的发行版)中分离出来,取而代之的是作为独立的 SDK、一组 jmods 或作为中央 Maven 存储库中可用的库依赖项(概述如下)https://openjfx.io),标准 Linux OpenJDK 发行版不需要包含 JavaFX。
If you want a pre-built JDK which includes JavaFX, consider the Liberica JDK distributions, which are provided for a variety of platforms.
如果您需要包含 JavaFX 的预构建 JDK,请考虑为各种平台提供的Liberica JDK 发行版。
Advice on Deployment for Substantial Applications
实质性应用部署建议
I advise using Java's self-contained applicationdeployment mode.
我建议使用 Java 的自包含应用程序部署模式。
A description of this deployment mode is:
这种部署模式的描述是:
Application is installed on the local drive and runs as a standalone program using a private copy of Java and JavaFX runtimes. The application can be launched in the same way as other native applications for that operating system, for example using a desktop shortcut or menu entry.
应用程序安装在本地驱动器上,并使用 Java 和 JavaFX 运行时的私有副本作为独立程序运行。该应用程序可以以与该操作系统的其他本机应用程序相同的方式启动,例如使用桌面快捷方式或菜单条目。
You can build a self-contained application either from the Oracle JDK distribution or from an OpenJDK build which includes JavaFX. It currently easier to do so with an Oracle JDK.
您可以从 Oracle JDK 发行版或从包含 JavaFX 的 OpenJDK 构建构建自包含应用程序。目前使用 Oracle JDK 更容易做到这一点。
As a version of Java is bundled with your application, you don't have to care about what version of Java may have been pre-installed on the machine, what capabilities it has and whether or not it is compatible with your program. Instead, you can test your application against an exact Java runtime version, and distribute that with your application. The user experience for deploying your application will be the same as installing a native application on their machine (e.g. a windows .exe or .msi installed, an OS X .dmg, a linux .rpm or .deb).
由于 Java 版本与您的应用程序捆绑在一起,因此您不必关心机器上可能预装了什么版本的 Java、它具有哪些功能以及它是否与您的程序兼容。相反,您可以针对确切的 Java 运行时版本测试您的应用程序,然后将其与您的应用程序一起分发。部署应用程序的用户体验将与在他们的机器上安装本机应用程序相同(例如,安装了 windows .exe 或 .msi、OS X .dmg、linux .rpm 或 .deb)。
Note:The self-contained application feature was only available for Java 8 and 9, and not for Java 10-13. Java 14, via JEP 343: Packaging Tool, is scheduled to again provide support for this feature from OpenJDK distributions.
注意:自包含应用程序功能仅适用于 Java 8 和 9,不适用于 Java 10-13。Java 14,通过JEP 343: Packaging Tool,计划再次从 OpenJDK 发行版提供对这个特性的支持。
Update, April 2018: Information on Oracle's current policy towards future developments
2018 年 4 月更新:有关 Oracle 当前针对未来发展的政策的信息
- The Future of JavaFX and Other Java Client Roadmap Updatesby Donald Smith, Sr. Director of Product Management, Oracle.
- Java Client Roadmap Update - March 2018an Oracle White Paper.
- JavaFX 的未来和其他 Java 客户端路线图更新,由 Oracle 产品管理高级总监 Donald Smith 撰写。
- Java 客户端路线图更新 - 2018 年 3 月Oracle 白皮书。
回答by Stathis Andronikos
According to Oracle integration of OpenJDK & javaFX will be on Q1-2014 ( see roadmap : http://www.oracle.com/technetwork/java/javafx/overview/roadmap-1446331.html). So, for the 1st question the answer is that you have to wait until then. For the 2nd question there is no other way. So, for now go with java swing or start javaFX and wait
根据 Oracle 集成 OpenJDK 和 javaFX 将在 2014 年第一季度(参见路线图:http: //www.oracle.com/technetwork/java/javafx/overview/roadmap-1446331.html)。因此,对于第一个问题,答案是您必须等到那时。对于第二个问题,别无他法。因此,现在使用 java swing 或启动 javaFX 并等待
回答by DeepSidhu1313
Try obuildfactory.
There is need to modify these scripts (contains error and don't exactly do the "thing" required), i will upload mine scripts forked from obuildfactory in next few days. and so i will also update my answer accordingly.
需要修改这些脚本(包含错误并且不完全执行所需的“事情”),我将在接下来的几天上传从 obuildfactory 分叉的我的脚本。所以我也会相应地更新我的答案。
Until then enjoy, sir :)
在那之前享受吧,先生:)
回答by Максим Шатов
As a quick solution you can copy the JavaFX runtime JAR file and those referenced from Oracle JRE(JDK)or any self-contained application that uses JavaFX(e.g. JavaFX Scene Builder 2.0):
作为一种快速解决方案,您可以复制 JavaFX 运行时 JAR 文件以及从Oracle JRE(JDK)或任何使用 JavaFX 的自包含应用程序(例如JavaFX Scene Builder 2.0)引用的文件:
cp <JRE_WITH_JAVAFX_HOME>/lib/ext/jfxrt.jar <JRE_HOME>/lib/ext/
cp <JRE_WITH_JAVAFX_HOME>/lib/javafx.properties <JRE_HOME>/lib/
cp <JRE_WITH_JAVAFX_HOME>/lib/amd64/libprism_* <JRE_HOME>/lib/amd64/
cp <JRE_WITH_JAVAFX_HOME>/lib/amd64/libglass.so <JRE_HOME>/lib/amd64/
cp <JRE_WITH_JAVAFX_HOME>/lib/amd64/libjavafx_* <JRE_HOME>/lib/amd64/
just make sureyou have the gtk 2.18 or higher
只要确保你有 gtk 2.18 或更高版本
回答by Vineel Kovvuri
For me this worked.
对我来说这有效。
$ sudo apt-get install openjfx
回答by Mauli
Also answering this question:
同样回答这个问题:
Where can I get pre-built JavaFX libraries for OpenJDK (Windows)
在哪里可以获得用于 OpenJDK (Windows) 的预构建 JavaFX 库
On Linux its not really a problem, but on Windows its not that easy, especially if you want to distribute the JRE.
在 Linux 上这不是一个真正的问题,但在 Windows 上它不是那么容易,特别是如果你想分发 JRE。
You can actually use OpenJFX with OpenJDK 8 on windows, you just have to assemble it yourself:
您实际上可以在 Windows 上使用 OpenJFX 和 OpenJDK 8,您只需要自己组装它:
Download the OpenJDK from here: https://github.com/AdoptOpenJDK/openjdk8-releases/releases/tag/jdk8u172-b11
从这里下载 OpenJDK:https: //github.com/AdoptOpenJDK/openjdk8-releases/releases/tag/jdk8u172-b11
Download OpenJFX from here: https://github.com/SkyLandTW/OpenJFX-binary-windows/releases/tag/v8u172-b11
从这里下载 OpenJFX:https: //github.com/SkyLandTW/OpenJFX-binary-windows/releases/tag/v8u172-b11
copy all the files from the OpenFX zip on top of the JDK, voila, you have an OpenJDK with JavaFX.
将 OpenFX zip 中的所有文件复制到 JDK 之上,瞧,您有一个带有 JavaFX 的 OpenJDK。
Update:
更新:
Fortunately from Azul there is now a OpenJDK+OpenJFX build which can be downloaded at their community page: https://www.azul.com/downloads/zulu-community/?&version=java-8-lts&os=windows&package=jdk-fx
幸运的是,Azul 现在有一个 OpenJDK+OpenJFX 版本,可以在他们的社区页面下载:https: //www.azul.com/downloads/zulu-community/?&version=java-8-lts&os=windows&package=jdk-fx