【发布时间】:2014-04-01 19:03:29
【问题描述】:
我正在为 ant 构建实现 maven 包装器。而用于构建项目的ant命令如下
ant -v -f build.xml -Darch=linux-java7 -Dconfig=/work/build.config -Doutput=/work/bldout/
现在我必须通过 maven 执行上述命令。我尝试使用“I want to execute shell commands from maven's pom.xml”和“http://sanchitbahal.wordpress.com/2011/09/19/maven-exec-plugin-vs-maven-antrun-plugin-for-running-command-line-tool/”来实现这一点
我在 pom.xml 中尝试的示例代码如下:
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>execute-shell</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>test.sh</executable>
<arguments>
<argument>ARG1</argument>
<argument>ARG2</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
但我无法弄清楚如何将命名参数(例如“-Darch=linux-java7”)作为参数传递给 build.xml
同样使用maven-antrun插件调用build.xml如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>run-target</id>
<phase>install</phase>
<configuration>
<target>
<ant antfile="build.xml" target="all" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
但在这里我也无法弄清楚如何将诸如“-Darch=linux-java7”之类的参数作为参数传递给 build.xml
我知道的是,我可以将命令放入 shell 脚本(在 .sh 文件中)并使用 maven-exec-plugin 调用 shell 脚本,但想知道是否可以不这样做。
【问题讨论】: