开发自己的Maven插件之三:使用插件

好,现在创建另一个Maven项目来使用第二篇创建的plugin.注意还是通过私服获取。

pom.xml配置如下:

<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>

注意,第二篇产生的代码里面类的注释里包含了@goal touch

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

因此,在应用程序中,可以在plugin的execution里面设置在compile阶段执行touch goal.

那么当运行mvn compile的时候,就能看到hello world字样显示在终端上。

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] ------------------------------------------------------------------------

当然,也可以在命令行里面显示的指定,不过有点罗嗦:

mvn com.freebird:plugin-example1:1.0:touch
格式是 groupId:artifactId:version:goal




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值