Maven integrates Ant

Source: Internet
Author: User
Tags echo message

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.