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