【发布时间】:2013-02-07 10:47:08
【问题描述】:
我有一个配置为使用 Maven 构建和运行的项目。该项目依赖于平台特定的原生库,我使用找到的策略here 来管理这些依赖项。
本质上,特定平台的 .dll 或 .so 文件被打包到一个 jar 中,并通过识别目标平台的分类器推送到 Maven 服务器。然后 maven-dependency-plugin 解压平台特定的 jar,并将本机库复制到目标文件夹。
通常我会使用mvn exec:java 来运行Java 程序,但exec:java 在与Maven 相同的JVM 中运行应用程序,这会阻止我修改类路径。由于必须将本机依赖项添加到类路径中,因此我不得不改用mvn exec:exec。这是pom的相关sn-p:
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Djava.library.path=target/lib</argument>
<argument>-classpath</argument>
<classpath />
<argument>com.example.app.MainClass</argument>
</arguments>
</configuration>
</plugin>
...
这适用于应用程序的默认配置,但我希望能够在命令行中指定一些可选参数。理想情况下,我想做这样的事情:
mvn exec:exec -Dexec.args="-a <an argument> -b <another argument>"
不幸的是,指定 exec.args 变量会覆盖我在 pom 中的参数(这是设置类路径和运行应用程序所必需的)。有没有解决的办法?在命令行指定一些可选参数而不覆盖我在 pom 中的内容的最佳方法是什么?
【问题讨论】: