如何使用JRE部署JavaFX 11 Desktop应用程序 [英] How to deploy a JavaFX 11 Desktop application with a JRE

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

问题描述

我有一个JavaFX(JDK 8)桌面业务应用程序,它使用Java Web Start进行部署。用户安装了Java 8,他们只需转到URL(我的AWS Linux服务器上的公共URL),然后下载/启动应用程序(使用Web Start)。我也可以通过将新JAR部署到服务器来轻松更新应用程序。一切运作良好。

I have a JavaFX (JDK 8) desktop business application, which uses Java Web Start for deployment. Users have Java 8 installed, and they simply go to the URL (a public URL on my AWS Linux server) and the application downloads / starts (using Web Start). I can easily update the application, too, by deploying new JARs to the server. Everything works well.

但是,Oracle已停止使用Java 11启动Web Start,并在2018年3月的Java客户端路线图更新白皮书中,他们建议捆绑JRE与应用程序(应用程序的概念与独立的JRE分开分发,因此很快就会消失。)。我不能依赖我的用户留在Java 8 for Web Start,即使他们仍然保持在8,Oracle也需要许可才能继续使用Java 8(我没有,可能非常昂贵,我更喜欢无论如何随着社区向JavaFX 11和OpenJDK移动。

However, Oracle has discontinued Web Start with Java 11, and in their "Java Client Roadmap Update" white paper, March 2018, they recommend bundling a JRE with the application ("The notion of an application being distributed separately from a standalone JRE is, therefore, quickly fading."). I cannot rely on my users to stay at Java 8 for Web Start, and even if they do remain at 8, Oracle requires a license to continue using Java 8 (which I do not have, can be very costly, and I’d prefer anyways to move with the community towards JavaFX 11 and OpenJDK).

我想迁移到JavaFX 11.我已经关注了OpenJFX的JavaFX11入门( https://openjfx.io/openjfx-docs/ ),使用OpenJDK 11.0.1和Gluon的JavaFX SDK 11.0 .1(在Netbeans 10vc2上),并且能够运行示例应用程序(在我看来,我应该能够很容易地将我的JavaFX 8代码移植到JavaFX 11)。


I would like to migrate to JavaFX 11. I have followed OpenJFX’s "Getting Started with JavaFX11" (https://openjfx.io/openjfx-docs/), using OpenJDK 11.0.1 with Gluon’s JavaFX SDK 11.0.1 (on Netbeans 10vc2), and have been able to get the sample applications to run (and appears to me I should be able to port my JavaFX 8 code to JavaFX 11, quite easily).

然而,这是我被迫坚持方向的地方。如何将其与JRE捆绑在一起并将其部署到我的最终用户(并提供应用程序更新)?那里有一个简单的方法(甚至是艰难的方式,有一些方向/指南)?

However, this is where I am stuck for direction. How do I bundle this with the JRE and deploy this to my end-users (and provide application updates)? Is there an easy way out there (or even a hard way, with some direction/guides)?

我可以花几百个小时在JavaFX 11中编写富有表现力,丰富且有用的桌面业务应用程序,但我该怎么做呢?

I can spend hundreds of hours writing expressive, rich, and useful desktop business applications in JavaFX 11, but what do I do then?

部署工具包(如JWrapper,InstallAnywhere等)是否适合这个Java 11的新时代? Gluon / openjfx.io可能有我错过的推荐或指南吗?我似乎无法从信誉良好的来源找到任何建议或指南,因为我们开发人员如何专注于编写前端代码,以便部署应用程序。

Are the deployment toolkits, like JWrapper, InstallAnywhere, etc, suited to this new era of Java 11? Does Gluon/openjfx.io perhaps have a recommendation or guide I missed? I cannot seem to find any recommendations or guides from reputable sources, for how us developers, who focus on writing the front-end code, are to deploy the applications.

谢谢您可以获得任何帮助或指导。

Thank you for any help or guidance.

推荐答案

现在的工作方式是,将程序转换为模块,然后链接 它适用于它所需的所有其他模块。

The way it works now is, you convert your program to a module, then "link" it to all the other modules it requires.

此链接过程的结果就是所谓的图像。图像实际上是一个文件树,其中包含一个带有一个或多个可立即运行的可执行文件的 bin 目录。这个树是你分发的,通常是zip或tar.gz。

The result of this linking process is what’s known as an image. An image is actually a file tree, which includes a bin directory with one or more ready-to-run executables. This tree is what you distribute, typically as a zip or tar.gz.

步骤是:


  1. 创建module-info.java

  2. 使用模块路径而不是类路径进行编译

  3. 从类创建jar ,像往常一样

  4. 使用JDK的 jmod 工具将jar转换为jmod

  5. 链接jmod及其所依赖的模块成图像

  1. Create a module-info.java
  2. Compile with a module path instead of a classpath
  3. Create a jar from classes, as usual
  4. Convert jar to a jmod with the JDK’s jmod tool
  5. Link that jmod, and the modules on which it depends, into an image



编写模块描述符



第一步是将应用程序转换为模块。最低限度,这需要在源代码树的顶部(即空包中)创建 module-info.java 。每个模块都有一个名称,通常与包名相同,但不一定是。所以,你的module-info.java可能如下所示:

Writing a module descriptor

The first step is to turn the application into a module. Minimally, this requires creating a module-info.java at the top of your source tree (that is, in the empty package). Every module has a name, which is often the same as a package name but doesn’t have to be. So, your module-info.java might look like this:

module com.mcs75.businessapp {
    exports com.mcs75.desktop.businessapp;

    requires java.logging;
    requires transitive javafx.graphics;
    requires transitive javafx.controls;
}



建筑



构建时,根本不指定类路径。而是指定模块路径。

Building

When you build, you don’t specify a classpath at all. Instead, you specify a module path.

模块路径是目录列表,而不是文件。每个目录都包含模块,这并不奇怪。隐式包含JDK的 jmods 目录。您需要包含的只是包含所需的非JDK模块的目录。在你的情况下,这至少意味着Gluon的JavaFX:

A module path is a list of directories, not files. Each directory contains, not surprisingly, modules. The jmods directory of the JDK is included implicitly. All you need to include is directories containing the non-JDK modules you need. In your case, that at least means Gluon’s JavaFX:

javac -Xlint -g -d build/classes --module-path /opt/gluon-javafx/lib \
    src/java/com/mcs75/desktop/businessapp/*.java

然后你用通常的方式创建一个jar:

Then you create a jar the usual way:

jar -c -f build/mybusinessapp.jar -C build/classes .

包含module-info.class的jar文件被视为模块化jar。

A jar file with a module-info.class in it is considered a modular jar.

创建一个jmod通常是一个简单的过程:

Creating a jmod is usually a simple process:

mkdir build/modules
jmod create --class-path build/mybusinessapp.jar \
    --main-class com.mcs75.desktop.businessapp.BuinessApplication \
    build/modules/mybusinessapp.jmod



链接



最后,使用JDK的 jlink 命令汇总所有内容:

Linking

Finally, you use the JDK’s jlink command to assemble everything:

jlink --output build/image \
    --module-path build/modules:/opt/gluon-javafx/lib \
    --add-modules com.mcs75.businessapp \
    --launcher MyBusinessApp=com.mcs75.businessapp

jlink 创建一个最小的JRE,它只包含您明确添加的模块(以及那些显式模块所需的模块)。 - add-modules 是指定要添加内容的必需选项。

jlink creates a minimal JRE, which contains only the modules you explicitly add (and the modules those explicit modules require). --add-modules is the required option that specifies what to add.

与其他JDK工具一样, - module-path 指定包含模块的目录。

As with other JDK tools, --module-path specifies directories containing modules.

- 启动器选项使最终图像树在其带有给定名称的 bin 目录中具有附加的可执行脚本(等于之前的部分)。因此, MyBusinessApp = com.mcs75.businessapp 表示创建名为MyBusinessApp的可执行文件,执行模块com.mcs75.businessapp。

The --launcher option causes the final image tree to have an additional executable script in its bin directory with the given name (the part before the equals). So, MyBusinessApp=com.mcs75.businessapp means "create an executable named MyBusinessApp, which executes the module com.mcs75.businessapp."

因为 jmod create 命令包含一个 - main-class 选项,Java会知道什么执行,就像在清单中声明Main-Class属性一样。如果需要,也可以在 - launcher 选项中明确声明要执行的类。

Because the jmod create command included a --main-class option, Java will know what to execute, just like declaring a Main-Class attribute in a manifest. It is also possible to explicitly declare a class to execute in the --launcher option if desired.

您要分发的是整个图像文件树的zip或tar.gz。用户应该运行的可执行文件位于映像的 bin 目录中。当然,您可以自由添加自己的可执行文件。只要保留图像树的结构,您也可以将其置于任何类型的安装程序中。

What you will want to distribute is a zip or tar.gz of the entire image file tree. The executable that the user should run is in the image’s bin directory. Of course, you are free to add your own executables. You are also free to place this into any kind of installer, as long as the image tree’s structure is preserved.

未来的JDK将具有打包工具,用于创建完善的本机安装程序。

A future JDK will have a packaging tool for creating full-fledged native installers.

由于图像包含本机二进制文件,因此您需要为每个平台创建一个图像。显然,一种选择是在Linux系统上构建映像,再在Windows系统上构建映像,再在Mac上构建映像。

Since the image includes native binaries, you will need to create an image for each platform. Obviously, one option is to build the image on a Linux system, and again on a Windows system, and again on a Mac, etc.

但是你也可以使用 jmod jlink 为其他平台创建图像,无论你在哪里建造。

But you can also use jmod and jlink to create images for other platforms, regardless of where you’re building.

只需要几个额外的步骤。首先,您将需要其他平台的JDK。将它们下载为档案(zip或tar.gz),而不是安装程序,并将它们解压缩到您选择的目录。

There’s only a few additional steps needed. First, you will need the JDKs for those other platforms. Download them as archives (zip or tar.gz), not installers, and unpack them to directories of your choice.

每个JDK定义一个平台字符串。这通常是 os - arch 的形式。该平台是 java.base 模块的属性;您可以通过检查该模块来查看任何JDK平台:

Each JDK defines a platform string. This is normally of the form os-arch. The platform is a property of the java.base module; you can see any JDK’s platform by examining that module:

jmod describe path-to-foreign-jdk/jmods/java.base.jmod | grep '^platform'

使用将该平台字符串传递给jmod命令--target-platform 选项:

mkdir build/modules
jmod create --target-platform windows-amd64 \
    --class-path build/mybusinessapp.jar \
    --main-class com.mcs75.desktop.businessapp.BuinessApplication \
    build/modules/mybusinessapp.jmod

最后,在链接时,你想明确包含其他JDK的 jmods 目录,因此jlink不会隐式包含自己的JDK模块:

Finally, when linking, you want to explicitly include the other JDK’s jmods directory, so jlink won’t implicitly include its own JDK’s modules:

jlink --output build/image \
    --module-path path-to-foreign-jdk/jmods:build/modules:/opt/gluon-javafx/lib \
    --add-modules com.mcs75.businessapp \
    --launcher MyBusinessApp=com.mcs75.businessapp

这篇关于如何使用JRE部署JavaFX 11 Desktop应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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