Reputation: 173
I am trying to run a maven project using the maven-exec-plugin and the exec goal (the java goal does not work for my purposes). However, there are two things that I need to be able to do, and I can't figure out how do both at the same time.
The first is that it needs (obviously) the module path. When I set the arguments in the pom, this works, and my program does run:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<!-- <version>3.0.0</version> is specified in parent module's <pluginManagement> -->
<executions>
<execution>
<id>cli</id>
<configuration>
<executable>java</executable>
<arguments>
<argument>-p</argument>
<modulepath/>
<argument>-m</argument>
<argument>dev.liambloom.checker.ui/dev.liambloom.checker.ui.cli.Main</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
However, when I do this, there is no way to pass in additional command line arguments to my program (unless I set them in the pom before every execution, which is an option, but an undesirable one).
The other option, which allows me to easily add arguments, is to call exec manually or with a batch file, like this:
@echo off
mvn exec:exec@cli -pl ui -Dexec.longModulepath="false" -Dexec.args="-p %modulepath -m dev.liambloom.checker.ui/dev.liambloom.checker.ui.cli.Main %*"
However, the %modulepath
argument (documented here), doesn't seem to be working. Here are a few lines from the detailed command output:
[DEBUG] Executing command line: [C:\Program Files\Java\openjdk-17\bin\java.exe, -p, %modulepath, -m, dev.liambloom.checker.ui/dev.liambloom.checker.ui.cli.Main]
Error occurred during initialization of boot layer
java.lang.module.FindException: Module dev.liambloom.checker.ui not found
Does anyone know how to either a.) pass arbitrary arguments in addition to the ones specified in the pom, or b.) make the %modulepath
argument work?
Upvotes: 1
Views: 419
Reputation: 173
Okay, so I've come up with a solution. It's not the greatest, but it works. My pom now contains the following:
<executions>
<execution>
<id>get-module-path-win</id>
<configuration>
<executable>cmd</executable>
<arguments>
<argument>/c</argument>
<argument>echo</argument>
<modulepath />
</arguments>
</configuration>
</execution>
<execution>
<id>get-module-path-unix</id>
<configuration>
<executable>sh</executable>
<arguments>
<argument>-c</argument>
<argument>echo $0</argument>
<modulepath />
</arguments>
</configuration>
</execution>
</executions>
and then I call the program through the following batch file (on windows):
@echo off
for /f "tokens=*" %%F in ('mvn exec:exec@get-module-path-win -pl ui -q -DforceStdout') do set modulepath=%%F
java -p %modulepath% -m dev.liambloom.checker.ui/dev.liambloom.checker.ui.cli.Main %*
And bash file on unix:
#!/bin/sh
java -p $(mvn exec:exec@get-module-path-unix -q -DforceStdout -pl ui) -m dev.liambloom.checker.ui/dev.liambloom.checker.ui.cli.Main "$@"
Upvotes: 0