javamavenjavafxopenjfx

Cannot run OpenJFX's non modular maven sample


Title is pretty self explanatory, I've downloaded the non-modular maven sample code for JavaFX from OpenJFX (from here) and I can't run it.

It compiles without any error but when I try to run it I get this error

[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------< org.openjfx:hellofx >-------------------------
[INFO] Building hellofx 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] >>> javafx-maven-plugin:0.0.6:run (default-cli) > process-classes @ hellofx >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hellofx ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ hellofx ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] <<< javafx-maven-plugin:0.0.6:run (default-cli) < process-classes @ hellofx <<<
[INFO] 
[INFO] 
[INFO] --- javafx-maven-plugin:0.0.6:run (default-cli) @ hellofx ---
[INFO] Toolchain in javafx-maven-plugin null

[ERROR] Command execution failed.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.691 s
[INFO] Finished at: 2022-12-07T08:56:47+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.openjfx:javafx-maven-plugin:0.0.6:run (default-cli) on project hellofx: Error: Command execution failed. Cannot run program "java" (in directory "/home/johan/Desktop/hellofx"): error=2, No such file or directory -> [Help 1]

Any idea is appreciated as I don't even understand the Cannot run program Java part. I ran the javafx:compile then the javafx:run in Maven.


Solution

  • Ensure your JAVA_HOME environmental variable is set correctly. This will allow the javafx-maven-plugin to find the correct java command needed to run your application.

    Follow this guide, choosing the relevant section for your OS:

    Also, use the current version of the maven JavaFX plugin, 0.0.8, though that is not your core issue.