我试图使用maven- exec -plugin和exec目标运行一个maven项目( java目标对我的目的不起作用)。然而,有两件事我需要能够做,我不知道如何同时做到这两件事。
首先,它需要(显然)模块路径。当我在pom中设置参数时,这是可行的,我的程序也运行了:
<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>但是,当我这样做时,没有办法将附加的命令行参数传递给我的程序(除非我在每次执行之前将它们设置在pom中,这是一个选项,但却是一个不可取的选项)。
允许我轻松添加参数的另一个选项是手动或使用批处理文件调用exec,如下所示:
@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 %*"然而,%modulepath参数(文档化的这里)似乎不起作用。下面是详细命令输出的几行代码:
[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有没有人知道如何。))除pom或b中指定的参数外,还传递任意参数)。使%modulepath参数有效吗?
发布于 2021-12-08 16:11:55
好吧,所以我想出了一个解决办法。这不是最棒的,但很管用。我的pom现在包含以下内容:
<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>然后通过以下批处理文件(在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 %*和unix上的bash文件:
#!/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 "$@"https://stackoverflow.com/questions/70250835
复制相似问题