Trying to run a JavaFX program with the exec-maven-plugin, rather than the javafx-maven-plugin.
The latter works flawlessly, for anyone interested the declaration is
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>org.openjfx.App</mainClass>
</configuration>
</plugin>
But I thought, why not try exec-maven-plugin too, maybe you can get it to work, too.
So I need to inject the module path into the java command line.
So I achieved this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>--module-path</argument> <!-- inject string into the command line -->
<modulepath/> <!-- inject the module path based on what's in the local maven .m2 repo -->
<argument>--add-modules</argument> <!-- inject string into the command line -->
<argument>javafx.controls,javafx.fxml,javafx.web,javafx.graphics,javafx.media</argument> <!-- inject string into the command line -->
<argument>-classpath</argument> <!-- inject string into the command line -->
<classpath/> <!-- inject dependencies from the local maven .m2 repo -->
<argument>org.openjfx.App</argument> <!-- the program -->
</arguments>
</configuration>
</plugin>
Running mvn -X exec:exec reveals that the generated command line is
java
@/home/aloy/IdeaProjects/compile_javafx/target/modulepath
--add-modules
javafx.controls,javafx.fxml,javafx.web,javafx.graphics,javafx.media
-classpath [correct classpath]
org.openjfx.App
This means the --module-path string was not injected.
Instead java is told to look for file @/home/aloy/IdeaProjects/compile_javafx/target/modulepath which has indeed been created.
This behavior is not documented at https://www.mojohaus.org/exec-maven-plugin/examples/example-exec-for-java-programs.html
But the JavaFX program can actually run!
Note that if one removes
<argument>--module-path</argument> <!-- inject string into the command line -->
then the module path is injected into the command line directly (instead of the reference to the file modulepath) but without option -p prepended, leading to failure. Really weird, it would be much better for the plugin to bail out at once with a clear message here.
Trying to run a JavaFX program with the
exec-maven-plugin, rather than thejavafx-maven-plugin.The latter works flawlessly, for anyone interested the declaration is
But I thought, why not try
exec-maven-plugintoo, maybe you can get it to work, too.So I need to inject the module path into the java command line.
So I achieved this:
Running
mvn -X exec:execreveals that the generated command line isThis means the
--module-pathstring was not injected.Instead java is told to look for file
@/home/aloy/IdeaProjects/compile_javafx/target/modulepathwhich has indeed been created.This behavior is not documented at https://www.mojohaus.org/exec-maven-plugin/examples/example-exec-for-java-programs.html
But the JavaFX program can actually run!
Note that if one removes
then the module path is injected into the command line directly (instead of the reference to the file
modulepath) but without option-pprepended, leading to failure. Really weird, it would be much better for the plugin to bail out at once with a clear message here.