Introduction: Ant is a process-oriented building tool, and Maven encapsulates the details of the build. This makes ant more flexible, but because it is tied to too much detail, reusability is poor and complex to use. MAVEN, which encapsulates the details, has a better reusability and is relatively simple to use, but loses flexibility at the same time.
Sometimes, we have this need, using MAVEN packaging, you can transfer this well-fought war packet to a remote server, or in the construction process to do some operations, and this operation is not easy to use MAVEN processing. Then what to do. The Maven ant plugin is applied. We have to thank Maven for its powerful plugin mechanism. Here are the simple steps:
First step: Configure in the project Pom file:
<!--ant Plugins--
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>package</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<ant antfile= "Build.xml" target= "Run" ></ant>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
In the <tasks> tab above, you can also write ant commands, but in order not to add too many ant commands to Maven's Pom, put ant in the file alone. Be aware that
1) The value in the <phase> tag must correspond to the life cycle of the MAVEN build project, such as the ant command here will be executed after MAVEN has finished the package. That is, tell Maven when to call the Ant command.
2) The <goal> here is run (which I have not studied in depth).
3) The Antfile property of the <ant> tag is the path to the ant configuration file, which is the relative path. The target property is the target name to be executed in the configuration file.
Step two: Build the Build.xml file in the Pom.xml sibling directory and write your own ant command. Such as:
<?xml version= "1.0" encoding= "UTF-8"?>
<project name= "Demo" >
<target name= "Run" >
<echo message= "Executive" ></echo>
</target>
</project>
Step three: Implement MAVEN's packaging commands, and here's what you can do online, or right-click the file in Eclipse to execute the MAVEN package command. You can then see that the "Execute" message is printed in the console.
Here, it's just a preliminary integration of MAVEN's Ant plug-ins, which can also refer to the Maven attribute in the ant configuration file, as well as other ant commands, some of which are tied to Maven's build lifecycle, The need for this can be studied under the following article: The official article on the plug-in, welcome you to shoot bricks, exchange.