JavaFX 和 OpenJDK [英] JavaFX and OpenJDK

查看:69
本文介绍了JavaFX 和 OpenJDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试决定是否可以为 Java 应用程序的用户界面切换到 JavaFX.我的大多数用户都会使用 Oracle JRE,现在它集成了 JavaFX.但是,有些正在使用 OpenJDK(在 linux 上).这个(旧)问题表明 OpenJDK 与 JavaFX 的处理非常糟糕.根据 this 问题,替代的 OpenJFX 只会在版本 9 中完全集成到 OpenJDK 中.所以我的问题是双重的:

  • OpenJDK 中的 JavaFX 支持是否仍然如此糟糕?
  • 如果是这样,是否有任何 Linux 发行版已经提供了 OpenJFX 包,这样用户就不必自己构建?

解决方案

JavaFX 是 OpenJDK 的一部分

JavaFX 项目本身是开源并且是OpenJDK 项目的一部分.

但是,OpenJDK 项目包括许多项目,包括孵化项目和其他项目,例如 OpenJFX,其源代码和实现并未作为某些 JDK/JRE 发行版(例如 Oracle JDK 11+ 实现和许多开源JDK Linux 软件包安装不包括 JavaFX 运行时).

现代 JavaFX 发行版是模块

JavaFX 不是大多数 JDK 11+ 下载的一部分,它通常由开发人员作为模块或单独的 SDK 下载.

专用于 JavaFX 11+,详见 https://openjfx.io 站点:

<块引用>

JavaFX 运行时可作为特定于平台的 SDK,或作为多个 jmod,或作为 Maven Central 中的一组工件提供.

这意味着通过在运行时模块路径中包含适当的 JavaFX 模块(可从 openjfx 或 Maven Central 获得),可以在受支持平台上运行的任何现代 JDK 中使用 JavaFX.

openjfx 提供的所有 JavaFX 模块都是开源实现,不包含封闭源代码.

为了向最终用户分发基于 JavaFX 的应用程序,建议打包一个基于 JDK 和 JavaFX 模块的运行时映像分发包+所需的依赖库代码和应用程​​序代码.对此包装的完整讨论超出了本答案的范围,但如果需要,可以创建纯粹基于开源 JDK+JavaFX+库+应用程序代码的发行版.有关运行时映像的更多(虽然不全面)信息,请参阅openjfx.io 文档这个.

2021 年 9 月更新

另外,请参阅相关问题:

其中涵盖了有关 Java 8 以及一些更高版本的信息.

2019 年 12 月更新

有关如何使用开源 JavaFX 的最新信息,请访问 https://openjfx.io.这包括使用 JavaFX 作为从现有 JDK 访问的模块化库的说明(例如 Open JDK 安装).

JavaFX 的开源代码库位于 https://github.com/openjdk/jfx.

在链接的源位置,您可以找到开放 JavaFX 的许可证文件(目前是这个 许可证 与 OpenJDK 的许可证匹配:GPL+classpath 例外).

该项目的 wiki 位于:https://wiki.openjdk.java.net/display/OpenJFX/Main

如果您想快速开始使用开放式 JavaFX,Bellsoft 的 Liberica JDK 发行版提供了预构建的 OpenJDK包含适用于各种平台的 OpenJFX 的二进制文件.

对于作为自包含应用程序的分发,Java 14 计划实施 JEP 343:打包工具,它支持原生包装格式,为最终用户提供自然的安装体验.这些格式包括 Windows 上的 msi 和 exe、macOS 上的 pkg 和 dmg,以及 Linux 上的 deb 和 rpm.",用于部署基于 OpenJFX 的应用程序,带有本机安装程序,没有其他平台依赖项(例如预安装的 JDK).


随着时间的推移可能会过时的旧信息

从 OpenJDK 存储库构建 JavaFX

您可以构建OpenJDK(包括JavaFX)的开放版本 完全来自源代码,不依赖于 Oracle JDK 或封闭源代码.

更新:使用从 OpenJDK 源预先构建的 JavaFX 发行版

正如对此问题的评论和另一个答案所述,Debian Linux 发行版提供了基于 OpenJDK 的 JavaFX 二进制发行版:

(据我所知,目前这只适用于 Java 8).

Open JDK 和 Oracle JDK 在 JavaFX 方面的区别

以下信息是为 Java 8 提供的.从 Java 9 开始,JavaFX 不推荐使用 VP6 编码Oracle WebStart/Browser 嵌入式应用程序部署技术也已弃用.因此,JavaFX 的未来版本,即使它们由 Oracle 分发,也可能不会包含任何非开源技术.

Oracle JDK 包含一些无法从 OpenJDK 使用的软件.与 JavaFX 相关的组件:

  • ON2 VP6 视频编解码器归 Google 所有,Google 尚未开源.
  • Oracle WebStart/Browser Embedded 应用部署技术.

这意味着 JavaFX 的开放版本无法播放 VP6 FLV 文件.这不是一个很大的损失,因为很难找到 VP6 编码器或以 VP6 编码的媒体.

其他更常见的视频格式,例如 H.264 可以在 JavaFX 的开放版本中正常播放(只要您在目标机器上预装了适当的编解码器).

WebStart/Browser Embedded 部署技术的缺乏确实与 OpenJDK 本身有关,而不是与 JavaFX 相关.该技术可用于部署非 JavaFX 应用程序.

如果开源社区为 Java(和其他软件)开发一种部署技术,完全取代 WebStart 和浏览器嵌入式部署方法,从而为应用程序分发提供良好的轻量级、低影响用户体验,那就太好了.我相信已经有一些项目开始为这样的目标服务,但它们还没有达到很高的成熟度和采用水平.

就我个人而言,我认为 WebStart/Browser Embedded 部署是遗留技术,目前有更好的方法来部署许多 JavaFX 应用程序(例如自包含应用程序).

2019 年 12 月更新:

已开发出适用于 JDK 11+ 的 WebStart 开源版本,可从 https://openwebstart.com.

谁需要创建包含 JavaFX 的 Linux OpenJDK 发行版

为基于 OpenJDK 的 Linux 发行版(例如 Redhat、Ubuntu 等)创建包的人员为包含 JavaFX 的 JDK 和 JRE 创建 RPM.那些软件发行商需要将生成的包放置在他们的标准发行代码存储库中(例如 fedora/red hat network yum 存储库).目前这还没有完成,但如果 Java 8 Linux 包在 2014 年 3 月发布时 Java 8 Linux 包不包含 JavaFX,我会感到非常惊讶.

更新,2019 年 12 月:

现在 JavaFX 已经从大多数二进制 JDK 和 JRE 发行版(包括 Oracle 的发行版)中分离出来,取而代之的是作为独立 SDK、一组 jmod 或从 中央 Maven 存储库(如https://openjfx.io),标准的 Linux OpenJDK 发行版就不需要包含 JavaFX.

如果您想要包含 JavaFX 的预构建 JDK,请考虑提供的 Liberica JDK 发行版适用于各种平台.

关于部署大量应用程序的建议

我建议使用 Java 的 自包含应用程序 部署模式.

对这种部署方式的描述是:

<块引用>

应用程序安装在本地驱动器上并作为独立运行程序使用 Java 和 JavaFX 运行时的私有副本.这应用程序可以以与其他本机相同的方式启动该操作系统的应用程序,例如使用桌面快捷方式或菜单项.

您可以从 Oracle JDK 发行版或包含 JavaFX 的 OpenJDK 版本构建自包含应用程序.目前使用 Oracle JDK 更容易做到这一点.

由于您的应用程序捆绑了一个 Java 版本,您不必关心机器上可能预装了哪个版本的 Java、它具有哪些功能以及它是否与您的程序兼容.相反,您可以针对确切的 Java 运行时版本测试您的应用程序,然后将其与您的应用程序一起分发.部署应用程序的用户体验将与在他们的机器上安装本机应用程序相同(例如,安装了 windows .exe 或 .msi、OS X .dmg、linux .rpm 或 .deb).

注意:自包含应用程序功能仅适用于 Java 8 和 9,不适用于 Java 10-13.Java 14,通过JEP 343:打包工具,计划再次从OpenJDK 发行版.

更新,2018 年 4 月:有关 Oracle 当前针对未来发展的政策的信息

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 this question, the alternative OpenJFX will only be fully integrated into OpenJDK in version 9. So my question is twofold:

  • 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?

解决方案

JavaFX is part of OpenJDK

The JavaFX project itself is open source and is part of the OpenJDK project.

However, the OpenJDK project includes many projects, including incubating projects and other projects, such as OpenJFX, whose source and implementation are not shipped as part of some JDK/JRE distributions (e.g. Oracle JDK 11+ implementations and many open-source JDK Linux package installations do not include JavaFX runtimes).

Modern JavaFX distributions are modules

JavaFX is not part of most JDK 11+ downloads, it is usually downloaded by developers as modules or a separate SDK.

Specifically for JavaFX 11+, as detailed on the https://openjfx.io site:

JavaFX runtime is available as a platform-specific SDK, or as a number of jmods, or as a set of artifacts in Maven Central.

This means that JavaFX can be used from any modern JDK running on a supported platform, by including the appropriate JavaFX modules (available from openjfx or Maven Central) on the runtime module path.

All JavaFX modules available from openjfx are open source implementations that contain no closed source code.

For distribution of JavaFX-based applications to end-users, it is advised to package a run-time image distribution based on the JDK and JavaFX modules + required dependent library code and application code. A full discussion of this packaging is out of scope for this answer, but one can create a distribution based purely on open-source JDK+JavaFX+library+application code if desired. See the openjfx.io documentation on run-time images for some more (though not comprehensive) information on this.

Update Sep 2021

Also, see the related question:

Which covers information regarding Java 8 and also some later versions.

Update Dec 2019

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).

The open source code repository for JavaFX is at https://github.com/openjdk/jfx.

At the source location linked, you can find license files for open JavaFX (currently this license matches the license for OpenJDK: GPL+classpath exception).

The wiki for the project is located at: https://wiki.openjdk.java.net/display/OpenJFX/Main

If you want a quick start to using open JavaFX, the Bellsoft's Liberica JDK distributions provide pre-built OpenJDK binaries that include OpenJFX for a variety of platforms.

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).


Older information that may become outdated over time

Building JavaFX from the OpenJDK repository

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.

Update: Using a JavaFX distribution pre-built from OpenJDK sources

As noted in comments to this question and in another answer, the Debian Linux distributions offer a JavaFX binary distibution based upon OpenJDK:

(currently this only works for Java 8 as far as I know).

Differences between Open JDK and Oracle JDK with respect to JavaFX

The following information was provided for Java 8. As of Java 9, VP6 encoding is deprecated for JavaFX and 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.

Oracle JDK includes some software that is not usable from the OpenJDK. The components that relate to 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.

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.

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).

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.

It would be great if the Open Source 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.

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).

Update Dec, 2019:

An open source version of WebStart for JDK 11+ has been developed and is available at https://openwebstart.com.

Who needs to create Linux OpenJDK Distributions which include JavaFX

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.

Update, Dec 2019:

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.

If you want a pre-built JDK which includes JavaFX, consider the Liberica JDK distributions, which are provided for a variety of platforms.

Advice on Deployment for Substantial Applications

I advise using Java's self-contained application deployment mode.

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.

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.

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).

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.

Update, April 2018: Information on Oracle's current policy towards future developments

这篇关于JavaFX 和 OpenJDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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