maven-antrun-plugin

http://maven.apache.org/plugins/maven-antrun-plugin/usage.html

Usage

Run

The maven-antrun-plugin has only one goal, run.

This allows Maven to run Ant tasks. To do so, there must be an existing project and maven-antrun-plugin must have its<target> tag configured (although it would still execute without the <target> tag, it would not do anything). Below is the template for maven-antrun-plugin'spom.xml.

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
          <execution>
            <phase> <!-- a lifecycle phase --> </phase>
            <configuration>
              <target>

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

              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

Moreover, you can add a script to each lifecycle phase, by duplicating the <execution/> section and specifying a new phase.

Ultimately, you could specify some Ant <target/> attributes in the <target/> tag. Only depends attribute in Ant<target/> is not wrapped.

[...]
<configuration>
  <target name="The name of the target"
    if="The name of the property that must be set in order for this task"
    unless="The name of the property that must NOT be set in order for this task"
    description="A short description of this target's function">

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

  </target>
<configuration>
[...]

Additional source directories

If your ant tasks generate additional source code that needs to be added to the build, you can use thebuild-helper-maven-plugin. The sourceRoot and testSourceRoot options of the antrun plugin have been deprecated.

Using maven properties

All of the properties available to maven are also available in the target configuration. However, you may want to call an external Ant build script using theant task. To avoid name conflicts, only a subset of the properties are passed to the external Ant build. These include all properties defined in theproperties section of the POM. It also includes prefixed versions of some of the commonly used Maven properties.

  maven.project.groupId
  maven.project.artifactId
  maven.project.name
  etc.

If the maven property you want to use is not available in an external file, you will have to redefine the property before callingant.

  <property name="maven.project.url" value="${project.url}"/>
  <ant antfile="build.xml"/>

Ant Expressions to Maven Expressions Mapping

Some Ant expressions have their respective counterparts in Maven. Thus, one can simply invoke the corresponding Maven expression instead of using maven-antrun-plugin to avoid the unneccessary overhead.

Ant ExpressionMaven Expression
Built-in Tasks 
Antmaven-antrun-plugin
AntCallmaven-antrun-plugin
Availableprofiles
BUnzip2maven-assembly-plugin
BZip2maven-assembly-plugin
Chmodmaven-assembly-plugin
Conditionprofiles
Copymaven-resources-plugin
Dependsetmaven-dependency-plugin
Earmaven-ear-plugin
Filtermaven-resources-pluginNote: Filter uses the @...@ token while maven-resources-plugin uses the  $... token
FixCRLFmaven-resources-plugin
GenKeymaven-jar-plugin
GUnzipmaven-assembly-plugin
GZipmaven-assembly-plugin
Jarmaven-jar-plugin
Javacmaven-compiler-plugin
Javadoc/Javadoc2maven-javadoc-plugin
LoadPropertiesmaven-resources-plugin
Manifestmaven-jar-plugin
Propertymaven-resources-plugin
Replacemaven-resources-pluginNote: Replace can specify its token while maven-resources-plugin uses the  $... token
Tarmaven-assembly-plugin
Unjarmaven-assembly-plugin
Untarmaven-assembly-plugin
Unwarmaven-assembly-plugin
Unzipmaven-assembly-plugin
Warmaven-war-plugin
Zipmaven-assembly-plugin
Optional Tasks 
Antlrmaven-antlr-plugin
Dependmaven-dependency-plugin
EJB Tasksmaven-ejb-plugin
FTPmaven-deploy-pluginNote: maven-deploy-plugin can only deploy unto the FTP
JavaCCmaven-compiler-plugin
JJDocmaven-compiler-plugin
JJTreemaven-compiler-plugin
JUnitmaven-surefire-plugin
JUnitReportmaven-surefire-report-plugin
ServerDeploymaven-deploy-plugin
Setproxymaven-deploy-plugin
Translatemaven-resources-pluginNote: Translate can specify its own tokens and can have a different encoding scheme for reading and writing files. maven-resources-plugin however uses the  $... annotation only and has only one encoding scheme for reading and writing

 

 

===========example

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
     <execution>
      <!-- move all .properties files from classes to conf directory -->
      <id>move-properties-to-conf</id>
      <phase>prepare-package</phase>
      <configuration>
       <target>
        <copy todir="${project.build.directory}/config">
         <fileset dir="${basedir}/src/main/config" includes="**.*" />
        </copy>
        <copy todir="${project.build.directory}/pkg">
         <fileset dir="${basedir}/src/main/scripts" includes="**.*" />
        </copy>
       </target>
      </configuration>
      <goals>
       <goal>run</goal>
      </goals>
     </execution>
     <execution>
      <id>default-cli</id>
      <configuration>
       <target name="sendtohermes" description="send source to Hermes">
        <delete file="${tarfile}" />
        <delete file="${tarfile}.Z" />
        <echo message="+++Fixing CRLF+++" />
        <fixcrlf srcdir="src/main/" eol="lf" />
        <tar destfile="${tarfile}" basedir="${basedir}" excludes=".svn/**, target/**, xxx.env, settings.xml" />
        <exec executable="compress" failοnerrοr="yes">
         <arg line="${tarfile}" />
        </exec>
        <echo message="${tarfile}.Z" />
        <echo>send to hermes</echo>
        <exec executable="send_to_hermes" failοnerrοr="yes">
         <arg file="${tarfile}.Z" />
        </exec>
       </target>
      </configuration>
      <goals>
       <goal>run</goal>
      </goals>
     </execution>
     <execution>
      <id>clean</id>
      <phase>clean</phase>
      <configuration>
       <target>
        <delete file="${tarfile}" />
        <delete file="${tarfile}.Z" />
       </target>
      </configuration>
      <goals>
       <goal>run</goal>
      </goals>
     </execution>
     <execution>
      <id>create-run-script</id>
      <phase>prepare-package</phase>
      <configuration>
       <target>
        <copy todir="${project.build.directory}/bin">
         <fileset dir="src/main/bin" includes="*.*sh" />
         <fileset dir="src/main/bin" includes="README*" />
        </copy>
        <!-- .sh script -->
        <copy file="${project.build.directory}/bin/start0.sh" tofile="${project.build.directory}/bin/start0.sh.classpath" />
        <replaceregexp file="${project.build.directory}/bin/start0.sh.classpath" match=".+\n(CLASSPATH=[^\n]+\n).+" replace="\1" flags="s" />
        <copy file="${project.build.directory}/bin/start0.sh" tofile="${project.build.directory}/bin/start0.sh.jvmargs" />
        <replaceregexp file="${project.build.directory}/bin/start0.sh.jvmargs" match=".+\n(EXTRA_JVM_ARGUMENTS=[^\n]+\n).+" replace="\1" flags="s" />
        <concat destfile="${project.build.directory}/bin/start.ksh">
         <fileset file="src/main/bin/start.sh.1.txt" />
         <fileset file="${project.build.directory}/bin/start0.sh.classpath" />
         <fileset file="${project.build.directory}/bin/start0.sh.jvmargs" />
         <fileset file="src/main/bin/start.sh.2.txt" />
         <fileset file="src/main/bin/start.sh.3.txt" />
        </concat>
        <delete>
         <fileset dir="${project.build.directory}/bin" includes="start0.*" />
        </delete>
       </target>
      </configuration>
      <goals>
       <goal>run</goal>
      </goals>
     </execution>
     <execution>
      <phase>package</phase>
      <goals>
       <goal>run</goal>
      </goals>
      <configuration>
       <tasks>
        <concat destfile="${basedir}/pkg/package.spec" fixlastline="true">
         <filelist files="ident.txt" dir="${basedir}/pkg" />
         <filelist files="${project.artifactId}.spec" dir="${project.build.directory}/rpm/SPECS" />
        </concat>
        <move todir="${basedir}">
         <fileset dir="${project.build.directory}/rpm/RPMS/noarch">
          <include name="**/*.rpm" />
         </fileset>
        </move>
       </tasks>
      </configuration>
     </execution>
    </executions>
    <dependencies>
     <dependency>
      <groupId>ant</groupId>
      <artifactId>optional</artifactId>
      <version>1.5.4</version>
     </dependency>
    </dependencies>
   </plugin>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值