Develop your own Maven plug-in 3: Use the plug-in

Source: Internet
Author: User

Well, now create another Maven project to use the plug-in created in article 2. Note that it is still obtained through the private server.

The configuration of POM. XML is as follows:

<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>com.mycompany</groupId>  <artifactId>mavenproject1</artifactId>  <version>1.0-SNAPSHOT</version>  <packaging>jar</packaging>  <name>mavenproject1</name>  <url>http://maven.apache.org</url>  <properties>    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  </properties>  <dependencies>    <dependency>      <groupId>junit</groupId>      <artifactId>junit</artifactId>      <version>3.8.1</version>      <scope>test</scope>    </dependency>  </dependencies>  <build>    <plugins>      <plugin><groupId>com.freebird</groupId><artifactId>plugin-example1</artifactId><version>1.0</version><executions>          <execution>            <phase>compile</phase>            <goals>              <goal>touch</goal>            </goals>          </execution>        </executions>      </plugin>    </plugins>  </build></project>

Note that the comments of the class in the second generated code contain @ goal touch

/** * Goal which touches a timestamp file. * * @goal touch *  * @phase process-sources */public class MyMojo    extends AbstractMojo

Therefore, in the application, you can set the execution of touch goal in the compile stage in the execution of the plugin.

When MVN compile is run, the Hello world is displayed on the terminal.

chenshu@chenshu-beijing:~/NetBeansProjects/mavenproject1$ mvn compile[INFO] Scanning for projects...[INFO]                                                                         [INFO] ------------------------------------------------------------------------[INFO] Building mavenproject1 1.0-SNAPSHOT[INFO] ------------------------------------------------------------------------[INFO] [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ mavenproject1 ---[debug] execute contextualize[INFO] Using 'UTF-8' encoding to copy filtered resources.[INFO] skip non existing resourceDirectory /home/chenshu/NetBeansProjects/mavenproject1/src/main/resources[INFO] [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ mavenproject1 ---[INFO] Nothing to compile - all classes are up to date[INFO] [INFO] --- plugin-example1:1.0:touch (default) @ mavenproject1 ---[INFO] hello world[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 0.971s[INFO] Finished at: Mon Jul 02 21:00:53 CST 2012[INFO] Final Memory: 7M/105M[INFO] ------------------------------------------------------------------------

Of course, you can also specify the display in the command line, but it is a bit wordy:

mvn com.freebird:plugin-example1:1.0:touch

Format: groupid: artifactid: Version: Goal

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.