maven-antrun-plugin插件

阅读数:90 评论数:0

跳转到新版页面

分类

应用软件

正文

虽然maven已代替了ant,成为Java领域事实上的构建标准,但在某些情况下,如果可以用ant命令,还是很方便的,借助maven-antrun-plugin插件,可以在maven执行时,额外执行ant脚本。

1、打包完成后,把构建结果复制到基他位置

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>package</id>
            <phase>package</phase>
            <configuration>
            <target>
                <echo message="copy package to deplay dir"/>
                <copy file="${basedir}/target/archbase-${profiles.evn}-${project.version}.war"
                    tofile="E:/Repositories/workspace/deplay/archbase.war"
                    overwrite="true"/>
            </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

(1)<phase>package</phase>表示插件要在maven的package时执行。

(2)<target></target>之间可以写任何ant支持的task。

2、执行外部命令

<plugin>  
    <artifactId>maven-antrun-plugin</artifactId>  
    <executions>  
        <execution>  
            <id>package</id>  
            <phase>package</phase>  
            <goals>  
                <goal>run</goal>  
            </goals>  
            <configuration>  
                <tasks>  
                    <echo message="make ..."/>  
                    <exec dir="src/main/c" executable="make" failonerror="true" />  
                </tasks>  
            </configuration>  
        </execution>  
        <execution>  
            <id>clean</id>  
            <phase>clean</phase>  
            <goals>  
                <goal>run</goal>  
            </goals>  
            <configuration>  
                <tasks>  
                    <echo message="make clean ..."/>  
                    <exec dir="src/main/c" executable="make" failonerror="true">  
                        <arg line="clean"/>  
                    </exec>  
                </tasks>  
            </configuration>  
        </execution>  
    </executions>  
</plugin>

3、引用外部的build.xml文件

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>compile</id>
            <phase>compile</phase>
            <configuration>
                <target>
                    <property name="compile_classpath" refid="maven.compile.classpath"/>
                    <property name="runtime_classpath" refid="maven.runtime.classpath"/>
                    <property name="test_classpath" refid="maven.test.classpath"/>
                    <property name="plugin_classpath" refid="maven.plugin.classpath"/>
                    <ant antfile="${basedir}/build.xml">
                        <target name="test"/>
                    </ant>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>


The build.xml:

<?xml version="1.0"?>
<project name="test6">
    <target name="test">
      <echo message="compile classpath: ${compile_classpath}"/>
      <echo message="runtime classpath: ${runtime_classpath}"/>
      <echo message="test classpath:    ${test_classpath}"/>
      <echo message="plugin classpath:  ${plugin_classpath}"/>
    </target>
</project>



相关推荐

Nexus是maven仓库管理器,可以使用它在本地架构一个maven仓库服务器。 http://www.sonatype.org/nexus/

目的 在你的maven项目中创建一个Docker镜像。比方说,build过程可以为java服务输出一个可以运行该服务的Docker镜像。 步骤 有两种配置方式,一种是通过Dockerfile文件,一种

&lt;mirror&gt; &lt;id&gt;alimaven&lt;/id&gt; &lt;name&gt;

Maven中的dependencyManagement元素提供了一种管理依赖版本号的方式。在dependencyManagement元素中声明所依赖的jar包的版本号等信息,那么所有<stron

在pom.xml中使用distributionManagement将项目打包上传到nexus私服(maven的一种远程私有仓库)。 <pre class="language-markup

一、概述 repositories配置jar仓库,pluginRepositories配置插件仓库。 二、通过项目pom.xml配置 <repositories> <repository>

dependencyManagement 只是声明依赖,并不实际引入,只有在子项目中写了该依赖项,并且没有指定具体版本,才会从父项目继承该项。 denpende

一、前置知识 1、settings.xml中的proxy、server、repository、mirror proxy 是服务器不能直接访问外网时需要设置的代理服务。 server 是服务器

在Maven的pom.xml文件中,存在如下两种build &lt;project&gt; &lt;buil

在构建Maven项目的时候,如果没有进行特殊配置,Maven会按照 标准的目录结构查找和处理各种类型文件。 src/main/java和src/test/java <p