在 jpackage 之后运行 JavaFX 应用程序 [英] running JavaFX application after jpackage

查看:31
本文介绍了在 jpackage 之后运行 JavaFX 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些非常菜鸟的问题.我尝试在 OpenJDK 14 中使用 jpackage 为我的测试应用程序创建安装.这是我所做的:

I have some really noob question. I tried to create installation for my test app with jpackage in OpenJDK 14. Here is what I did:

首先,使用

jlink --module-path "C:Javajavafx-sdk-14lib" --add-modules javafx.controls,javafx.fxml --output hellomyjre

然后就成功了.我从运行配置复制了我的 Eclipse 中的参数.之后用jpackage进行安装

and that was successful. I copied arguments from my Eclipse from Run Configurations. After that made installation with jpackage

jpackage --name HelloFX --input hello --main-jar HelloFX.jar --runtime-image hellomyjre

创建的 .msi 文件,我运行它并在我的 Win10 应用程序中创建了条目.当然,我不知道如何在 windows 菜单中找到它,但它放在我的 C:Program FilesHelloFX 中.我找到了带有 Duke 图像的图标和应用程序文件,当我尝试运行应用程序时,会弹出无法启动 JVM"消息.

That created .msi file, I run it and it created entry in my Win10 applications. Of course, I have no idea how to find that in windows menu, but it is placed in my C:Program FilesHelloFX. I located Icon and Application file with Duke image, when I tried to run application meesage "Failed to launch JVM" pop up.

谁能帮帮我,我做错了什么?我真的很想完成这项工作并深入研究 JavaFX.

Can someone help me, what am I doing wrong? I really want to make this work and dive deeply in JavaFX.

推荐答案

JavaFX SDK 中包含的 JavaFX JAR 不包含本机代码.相反,所述代码位于 bin 目录中.这意味着由 jlink 创建的自定义运行时映像没有运行 JavaFX 所需的本机代码.您有两个选择:

The JavaFX JARs included with the JavaFX SDK do not include the native code. Instead, said code is in the bin directory. That means your custom runtime image created by jlink does not have the necessary native code to run JavaFX. You have two options:

  1. 从 Gluon 下载 的 JMOD 文件,并在创建自定义运行时映像时使用这些文件.您可以将 JMOD 文件放在 --module-path 而不是常规 JAR 文件中.

  1. Download the JMOD files from Gluon and use those when creating the custom runtime image. You would put the JMOD files on the --module-path instead of the regular JAR files.

  • 请注意,获取 JMOD 文件的另一种方法是使用包含 JavaFX 的 JDK 发行版.此类发行版可能不再由 Oracle 提供,但其他发行商仍会提供(例如 Azul Zulu、BellSoft Liberica 等).如果您有一个包含 JavaFX 的 JDK,那么您不需要将 JavaFX 放在 --module-path 上,只需确保在打包和执行期间解析 JavaFX 模块(通过 需要 指令或--add-modules 参数).
  • Note another way to get the JMOD files is to use a JDK distribution that includes JavaFX. Such distributions may no longer be provided by Oracle but other distributors still offer them (e.g. Azul Zulu, BellSoft Liberica, etc.). If you have a JDK that includes JavaFX then you don't need to place JavaFX on the --module-path, just make sure the JavaFX modules are resolved while packaging and during execution (via requires directives or --add-modules arguments).

使用发布到 Maven Central 而不是 SDK 的 JavaFX JAR.Maven Central JAR 嵌入了本机代码.

Use the JavaFX JARs that are published to Maven Central instead of the SDK. The Maven Central JARs embed the native code.

在这两种情况下,请确保为您的操作系统使用 JMOD/JAR 文件 - JavaFX 是特定于平台的.

In both cases, make sure to use the JMOD/JAR files for your operating system—JavaFX is platform-specific.

我相信第一个选项是最好的.当使用带有 jlink 的 JMOD 文件时,本地代码包含在自定义运行时映像中,其方式与特定于 JRE 的本地代码相同.如果您使用第二种方法,本机代码仍将包含在自定义运行时映像中,但必须将其提取到您计算机上的某个位置(例如 /.openjfx)在它可以使用之前1.换句话说,第一个选项更干净.

I believe the first option is the best. When using JMOD files with jlink the native code is included with the custom runtime image in the same way as the native code specific to the JRE. If you use the second approach the native code will still be included with the custom runtime image but it will have to be extracted to some location on your computer (e.g. <user-home>/.openjfx) before it can be used1. In other words, the first option is cleaner.

1.请注意,此提取由 JavaFX 自动完成.

这篇关于在 jpackage 之后运行 JavaFX 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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