代码之家  ›  专栏  ›  技术社区  ›  Armand

如何从Maven2运行蚂蚁目标?

  •  3
  • Armand  · 技术社区  · 14 年前

    mvn antrun:run 不能让它跑。


    <project>
        ...
        <build>
            <plugins>
                ...
                <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>myExecution</id>
                            <phase>deploy</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <tasks>
                                    <ant target="myTarget" inheritRefs="true">
                                        ...
                                    </ant>
                                </tasks>
                            </configuration>
                        </execution>
                    </executions>
    
                    <dependencies>
                        ...
                    </dependencies>
                </plugin>
                ...
            </plugins>
            ...
        </build>
        ...
    </project>
    
    4 回复  |  直到 9 年前
        1
  •  7
  •   Pascal Thivent    14 年前

    如何使用命令行中的antrun插件运行特定目标?

    严格地回答这个问题,你不能,你也不能。

    你可以做的是:

    configuration

    <plugin>
       <artifactId>maven-antrun-plugin</artifactId>
       <configuration>
           ....
       </configuration>
    </plugin>
    

    在调用插件时将使用此配置(无论如何调用插件:从cli,生命周期的一部分)。

    2。提供执行级别 (你就是这么做的)

    <plugin>
       <artifactId>maven-antrun-plugin</artifactId>
       <executions>
           <execution>
               <id>myExecution</id>
               <phase>deploy</phase>
               <goals>
                   <goal>run</goal>
               </goals>
               <configuration>
                   <tasks>
                       <ant target="myTarget" inheritRefs="true">
                           ...
                       </ant>
                   </tasks>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    然后调用插件绑定到的阶段( deploy

    三。提供执行级别 配置 特别的 default-cli 执行Id

    <plugin>
       <artifactId>maven-antrun-plugin</artifactId>
       <executions>
           <execution>
               <id>default-cli</id>
               <configuration>
                   <tasks>
                       <ant target="myTarget" inheritRefs="true">
                           ...
                       </ant>
                   </tasks>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    MNG-3401 ),可以在POM中配置直接从命令行调用的目标,而不必使用名为 默认cli

    但无论如何,您不能调用特定的Ant target 在一个 元素。你可以用配置文件来实现一些接近的东西,但是,如果你真的想朝这个方向发展,我的建议是使用Ant。

    工具书类

        2
  •  2
  •   Gima    10 年前

    在pom.xml中:

    ...
    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <configuration>
            <target>
                <ant target="trampoline" />
            </target>
        </configuration>
    </plugin>
    ...
    

    ...
    <target name="trampoline">
        <echo message="Executing target '${mvnAntTarget}'"/>
        <antcall target="${mvnAntTarget}" />
    </target>
    
    <target name="testTarget">
        <echo message="Yay, I'm a test target.."/>
    </target>
    ....
    

    然后,通过运行:

    $ mvn antrun:run -DmvnAntTarget=testTarget
    

    蚂蚁的 testTarget 将运行。

        3
  •  1
  •   Code Lღver Ionut Rusen    11 年前

    http://docs.codehaus.org/display/MAVENUSER/Antrun+Plugin 基本上是用一个常规的build.xml来编写ant目标。 然后定义一个 <target> 在“配置”下,动态确定构建文件名和目标名,并执行

    <ant andfile="${buildFile}" target="${targetName}" inheritAll="true" inheritRefs="true"/>
    
        4
  •  0
  •   Damien    14 年前

    我不太确定这是它不起作用的原因,但您使用的语法已被弃用。你应该有这样的东西:

    <configuration>
      <target name="myTarget">
        <!--
          Place any Ant task here. You can add anything
          you can add between <target> and </target> in a
          build.xml.
        -->    
      </target>
    <configuration>
    

    更多详情请点击此处: http://maven.apache.org/plugins/maven-antrun-plugin/usage.html