2011-12-12 54 views
0

我的项目运行具有以下命令完美的罚款:如何通过maven执行简单的蚂蚁通话?

C:\project\<project_name>\ant -lib ant\lib -buildfile applications/<sub-project-path>/ant/build.xml deploy 

但是,如果我在POM包装这个命令无论是在Maven的antrun-插件或者exec-Maven的插件,我得到的各种路径的问题。

对于maven-antrun-plugin,似乎某些属性由于路径问题而无法加载。在exec-maven-plugin中,似乎蚂蚁目标从未正确传入。
有人可以请教如何我可以应用这在一个POM文件?非常感激。

这是我的exec 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> 
+0

好的,我已经找到了这里的问题。显然在争论中,你不能传递空间。所以这个问题解决了。不过,我仍然很好奇如何在antrun-plugin中写这个。这是pom文件,它不知道如何解析路径。 –

回答

0

你应该通过所需的依赖直接进入antrun插件声明,之后<executions>元素。

<plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>exec-maven-plugin</artifactId> 
     <version>1.2.1</version> 
     <executions> 
      ... 
     </executions> 
     <dependencies> 
      <dependency> 
      <groupId>ant-contrib</groupId> 
      <artifactId>ant-contrib</artifactId> 
      <version>${ant-contrib.version}</version> 
      <exclusions> 
       <exclusion> 
       <groupId>ant</groupId> 
       <artifactId>ant</artifactId> 
       </exclusion> 
      </exclusions> 
      </dependency> 
      <dependency> 
      <groupId>org.apache.tomcat</groupId> 
      <artifactId>jasper</artifactId> 
      <version>${tomcat.compile.version}</version> 
      </dependency> 
      <dependency> 
      <groupId>com.sun</groupId> 
      <artifactId>tools</artifactId> 
      <version>${java.version}.0</version> 
      <scope>system</scope> 
      <systemPath>${jdk.home}/tools.jar</systemPath> 
      </dependency> 
     </dependencies> 
    </plugin> 

我已经在我们的项目中使用了一些库,以便您举个例子。请注意,如果您的构建使用了一些非标准(即java.lang以外的Java API类),则必须通过tools.jar作为依赖关系。

另外,如果你使用ant-contrib不要忘记排除ant作为依赖,因为它依赖于一些古老的蚂蚁版本,你会得到一个版本冲突。

另一个烦人的事情是,直接分配给插件执行的依赖不属于POM的<dependencyManagement>,所以你必须拼出精确的版本。一种解决方法是在与中心<dependencyManagement>相同的位置声明版本属性,并使用属性而不是硬编码版本。

1

还没有尝试过,但你可以做一些类似于maven antrun插件example中记录的内容。

<plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-antrun-plugin</artifactId> 
     <version>1.7</version> 
     <executions> 
      <execution> 
      <id>ant</id> 
      <phase>process-resources</phase> 
      <configuration> 
       <target> 
       <ant antfile="${basedir}/<project-path>/build.xml"> 
        <target name="deploy"/> 
       </ant> 
       </target> 
      </configuration> 
      <goals> 
       <goal>run</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 

不知道你想传递作为参数在上面的代码片段-lib什么库,但同样可以声明为plugindependencies

请注意,这个插件并不关心系统中是否存在ant安装。它下载必要的ant库。