0

I've packaged a JavaFx (14) project with jpackage for deployment in .exe setup.

The project dependencies are:

  • Java 14.0.2
  • JavaFx 14.0.2.1
  • JRE 1.8.0_271 (removed)

So, during my deployment on several machines (approximately 6), it was successful on several, but on others I have this error:

JVM can not launch

although all the dependencies have been properly installed on these machines as well as the environment variables well defined.

Can someone help me about it


After some fixes (mentionned by @Slaw and @mipa, I generated a new package, install it. But when I run the software (myApp.exe), I've this error

Failed to lunch JVM

After some research about it, the solution was to create a batch file with java command that will run the .jar file located on the C:\Program Files\ software folder

cd "C:\Program Files\software\app"
java --module-path "C:\Program Files\Java\javafx-sdk-14.0.2.1\lib" --add-modules=ALL-MODULE-PATH --add-exports javafx.graphics/com.sun.javafx.sg.prism=ALL-UNNAMED -jar software.jar

I've done it and it run the software very well, but is there another optimize solution to run directly the software without the batch file?

Cause on some computers, the batch didn't run the software, returning that same error: Failed to lunch JVM

Please, help

  • 1
    Why are you using JRE 8 if you're developing with Java/JavaFX 14? I'm also not clear how you're using `jpackage` yet somehow depend on JRE 8 (or any external JRE for that matter). – Slaw Jan 23 '21 at 21:13
  • 1
    When you properly use jpackage to create an .exe you will not have any dependencies on your deployment targets anymore. As @Slaw already said - your whole setup looks more than strange. – mipa Jan 24 '21 at 11:25
  • @Slaw thanks for your remarks, I just read that the Java Runtime Environment was discontinued with Java 11. Since 14 > 11, there is no JRE for Java 14. So i'll fix it. – Jeff Ngnoulaye Jan 24 '21 at 16:09
  • Alright @mipa I'll fix my setup and try again the packaging with jpackage – Jeff Ngnoulaye Jan 24 '21 at 16:11
  • If you have to manually add `--module-path` and `--add-modules` then you failed to include JavaFX when packaging your application. In short, you need to tell `jpackage` to include JavaFX. Make sure you point it to the JMOD files rather than the JAR files. You can get the JMOD files from the same place you got the JavaFX SDK (i.e. Gluon). You may wish to read this as well: https://docs.oracle.com/en/java/javase/15/jpackage/packaging-overview.html#GUID-C1027043-587D-418D-8188-EF8F44A4C06A – Slaw Jan 24 '21 at 18:00
  • Alright, I'll checkt it and fix the incluse of JavaFx with JMOD – Jeff Ngnoulaye Jan 25 '21 at 15:44
  • JavaFX 14 is no more available on Gluon.io, can someone lead me what to do? Upgrade my project to 16? – Jeff Ngnoulaye Jan 25 '21 at 16:05
  • The current release of JavaFX is 15.0.1. Version 16 is early-access. You should be able to upgrade to the current release with no issues (in fact, it's encouraged you upgrade so you get all the latest patches, including security patches, and features). Though if you rely on private code (as your `--add-exports` code suggests) then some things _might_ break (you'd have to test). – Slaw Jan 25 '21 at 16:12

1 Answers1

0

If you have to manually launch the application with --module-path and --add-modules then you failed to include JavaFX while packaging the application, or at least failed to include JavaFX correctly. Keep in mind that JavaFX is modular, even if your code is not. So when you package your application you should tell jpackage to treat JavaFX as modules.

First, you should get the JavaFX JMOD files. You can get them in one of at least two ways:

  1. Download the JMOD files from Gluon (the same place you downloaded the JavaFX SDK from).
  2. Install and use a JDK that includes JavaFX (e.g. from Zulu Community, BellSoft Liberica, etc.).
    • With this option you don't need the JavaFX SDK to begin with.

You want the JMOD files because they package the native code (and other things, such as licenses) with the Java code. This allows jlink (used behind-the-scenes by jpackage) to gracefully include the native code with the custom run-time image. Also, don't forget that JavaFX (and by extension the JMOD files) is platform-specific. And jpackage can only create applications for the operating system it's invoked on.

After getting the JMOD files you'll want to package your application. Let's assume your code is not modular (you use -jar in your question) and you've packaged your code into a JAR file. The following command should be the minimum you need to use jpackage:

jpackage --type app-image --module-path <path-to-jmods> --add-modules <needed-modules> 
         --input <dir-containing-your-jar-file> --main-jar <your-jar-file>
         --main-class <your-main-class> --dest <your-output-location>

Some notes:

  • If you install and use a JDK with JavaFX included then you won't need --module-path. At least not for JavaFX.

  • I'm not sure what modules your application needs (for the --add-modules option). You use ALL-MODULE-PATH but I doubt you need everything.

  • Not positive, but I believe if you have a Main-Class attribute in your JAR file's manifest then --main-class is not needed.

  • If you truly need the --add-exports argument then you can use:

    --java-options="--add-exports javafx.graphics/com.sun.javafx.sg.prism=ALL-UNNAMED"
    
  • If you make your code modular you can also get rid of the --add-modules argument. Instead you'd put your module (and any modules not in the JDK) on the --module-path and replace --input, --main-jar, and --main-class with --module-path and --module.

    • In this case --input no longer seems necessary. However, if you had other files needed by your application (e.g. security policy files) then you may still need --input.

See the JPackage User Guide for more information. There are many ways to customize your application described in the guide that are not mentioned in this answer.

If all this still doesn't solve the "Failed to launch JVM" error on every computer then you're going to need to do further debugging. The first thing you want is to know the actual error causing the problem. I can think of at least two ways to do this:

  1. Add logging to your application. Log to a file.
  2. Configure jpackage to make your application console-based. Then launch the application from the console to see any output. If you're having issues seeing the output then you can redirect the standard/error streams to a file or use options that tell the console not to open a new window.
Slaw
  • 37,820
  • 8
  • 53
  • 80
  • I've adjust my jpackage command to this: ```jpackage --type app-image --module-path "C:\Program Files\Java\javafx-jmods-15.0.1" --add-modules javafx.controls,javafx.fxml,javafx.web,java.logging --input C:\Users\ngnou\OneDrive\Documents\NetBeansProjects\EBB-App\dist --main-jar EBB-App.jar --main-class ebbapp.Main --dest C:\Users\ngnou\OneDrive\Documents\NetBeansProjects\Deploy --java-options "--add-exports javafx.graphics/com.sun.javafx.sg.prism=ALL-UNNAMED"``` – Jeff Ngnoulaye Jan 26 '21 at 10:52
  • The image has well been generated, but when I run **Main.exe**, nothing happens, it doesn't run the app. – Jeff Ngnoulaye Jan 26 '21 at 10:54
  • Even the **.exe** package installed, doesn't run When run ```java -jar EBB-App.jar``` (the pathe is the software app folder on C:), it's returns: ```Error: JavaFX runtime components are missing, and are required to run this application``` – Jeff Ngnoulaye Jan 26 '21 at 13:25
  • I can't reproduce the problem. I tested out the `jpackage` command I put in the answer and it worked for me. Did you point to the JMOD files? The JAR files from the SDK don't include the native code. The JMOD files do. So do the JAR files _from Maven Central_, but that isn't as clean as the JMOD files. Did you try the debugging advice at the end of the answer? Also, BellSoft Liberica does include JavaFX if you download the "Full JDK". – Slaw Jan 26 '21 at 18:20
  • Looking at your last comment again, why did you use `> java -jar EBB-App.jar`? You've created an executable. You should have done something like `> app-name.exe`. – Slaw Jan 27 '21 at 23:06
  • Hello @Slaw, I installed Java 15 from **BellSoft Liberica**, and updated _VM options_ and _jpackage command_ as you've specified in your answer. But when I run the **.exe** executable, the software doesn't run, but when i do `> java -jar EBB-App.jar`, it runs well. – Jeff Ngnoulaye Feb 06 '21 at 19:27
  • Here is my _jpackage command_: `jpackage --type app-image --add-modules javafx.controls,javafx.fxml,javafx.web,java.logging --input C:\Users\ngnou\OneDrive\Documents\NetBeansProjects\EBB-App\dist --main-jar EBB-App.jar --dest C:\Users\ngnou\OneDrive\Documents\NetBeansProjects\Deploy` – Jeff Ngnoulaye Feb 06 '21 at 20:11