首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Maven exec插件的%modulepath似乎无法工作

Maven exec插件的%modulepath似乎无法工作
EN

Stack Overflow用户
提问于 2021-12-06 19:22:34
回答 1查看 132关注 0票数 0

我试图使用maven- exec -plugin和exec目标运行一个maven项目( java目标对我的目的不起作用)。然而,有两件事我需要能够做,我不知道如何同时做到这两件事。

首先,它需要(显然)模块路径。当我在pom中设置参数时,这是可行的,我的程序也运行了:

代码语言:javascript
复制
<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,如下所示:

代码语言:javascript
复制
@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参数(文档化的这里)似乎不起作用。下面是详细命令输出的几行代码:

代码语言:javascript
复制
[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参数有效吗?

EN

回答 1

Stack Overflow用户

发布于 2021-12-08 16:11:55

好吧,所以我想出了一个解决办法。这不是最棒的,但很管用。我的pom现在包含以下内容:

代码语言:javascript
复制
<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上)调用程序:

代码语言:javascript
复制
@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文件:

代码语言:javascript
复制
#!/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 "$@"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70250835

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档