running JavaFX application after jpackage

微笑、不失礼 提交于 2020-07-28 04:15:10

问题


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:

first, created custom JRE with

jlink --module-path "C:\Java\javafx-sdk-14\lib" --add-modules javafx.controls,javafx.fxml --output hello\myjre

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 hello\myjre

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 Files\HelloFX. I located Icon and Application file with Duke image, when I tried to run application meesage "Failed to launch JVM" pop up.

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


回答1:


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

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

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

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. Note this extraction is done automatically by JavaFX.



来源:https://stackoverflow.com/questions/61294243/running-javafx-application-after-jpackage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!