maven-antrun-plugin usage example

It is an ordinary test project
Directory structure
Insert picture description here
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

There
is a main function in TestMain

Guess you like

Origin blog.csdn.net/qq_35189120/article/details/105678245