Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Module path" needs additional documentation! #448

Open
dtonhofer opened this issue Sep 26, 2024 · 0 comments
Open

"Module path" needs additional documentation! #448

dtonhofer opened this issue Sep 26, 2024 · 0 comments

Comments

@dtonhofer
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant