maven-antrun-plugin 使用例子

就是一个普通的测试项目
目录结构
在这里插入图片描述
pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>AntTest</groupId>
    <artifactId>anttest</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.8</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <id>compile</id>   <!--唯一id可以随意改变不可重复 -->
                        <phase>compile</phase><!--生命周期 -->
                        <configuration>
                            <target>
                                <property name="maven_project_url" value="${project.url}"/>
                                <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"/>

                                <!--加载配置文件-->
                                <loadproperties srcFile="${project.build.outputDirectory}\application.properties">
                                </loadproperties>

                                <echo message="jjw name:  ${jjw.name}"/>

                                <ant antfile="build.xml">  <!--默认自动继承当前页的属性-->
                                    <target name="callProjectC"></target>
                                </ant>

                                <!--ant 参考地址:http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html-->
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>TestMain</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>

    </build>

</project>

xml`







<target name="callProjectC">
    <echo message="In projectA calling projectC"/>
    <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>

`

application.properties

jjw.name=jjw

TestMain
里面就一个main 函数

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值