我的项目使用以下命令完美运行:
C:\project\<project_name>\ant -lib ant\lib -buildfile applications/<sub-project-path>/ant/build.xml deploy
但是,如果我在pom中的maven-antrun-plugin或exec-maven-plugin中包装此命令,我会遇到各种路径问题 .
对于maven-antrun-plugin,由于路径问题,似乎无法加载某些属性 . 在exec-maven-plugin中,似乎ant目标从未正确传递过 .
有人可以建议我如何在pom文件中应用它吗?非常感激 .
这是我执行的pom:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>ant</executable>
<workingDirectory>${basedir}</workingDirectory>
<arguments>
<argument>'-lib ant/lib'</argument>
<argument>'-buildfile $basedir/<project-path>/build.xml'</argument>
<argument>deploy</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
2 回答
您应该在
<executions>
元素之后直接将所需的依赖项传递给antrun插件声明 .我已经包含了一些我在项目中使用的库,所以你有一个例子 . 请注意,如果您的构建使用某些非标准(即
java.lang
之外的东西)Java API类,则必须将tools.jar
作为依赖项传递 .另外,如果您使用
ant-contrib
,请不要忘记将ant
排除为依赖项,因为它依赖于某些古老版本的ant,您将获得版本冲突 .另一个令人讨厌的事情是,直接分配给插件执行的依赖项不是POM的
<dependencyManagement>
的一部分,所以你必须拼出精确的版本 . 一种解决方法是在与中央<dependencyManagement>
相同的位置声明版本属性,并使用属性而不是硬编码版本 .没试过,但是你可以做类似于maven antrun插件example中记载的类似的东西 .
不确定您希望在上面的代码段中的
-lib
中作为参数传递哪个库,但同样可以声明为plugin
dependencies
.请注意,此插件并不关心系统上是否存在ant安装 . 它下载必要的ant库 .