maven使用插件

 

官网:

http://maven.apache.org/

点击Maven plugins

plugins 

http://maven.apache.org/plugins/index.html

点击一个plugins 如compiler

http://maven.apache.org/plugins/maven-compiler-plugin/

通过Goals Overview可以查看目标

再点击Source Repository可以查看下载源码的方法

点击Examples下的链接可以查看如何使用

 

source插件可以对源码打包

http://maven.apache.org/plugins/maven-source-plugin/

编辑pom.xml

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>2.2.1</version>
      </plugin>
    </plugins>
  </build>
  ...
</project>

 

pom.xml--右键--Run As --  Maven build -- 在golas输入source:jar-no-fork -- Run

这样就打出个源码包

 

如果在parent中配置

 

<build>
  	<pluginManagement>
	    <plugins>
	      <plugin>
	        <groupId>org.apache.maven.plugins</groupId>
	        <artifactId>maven-source-plugin</artifactId>
	        <version>2.2.1</version>
	        <executions>
	        	<execution>
	        		<phase>package</phase>
	        		<goals><goal>jar-no-fork</goal></goals>
	        	</execution>
	        </executions>
	      </plugin>
	    </plugins>
    </pluginManagement>
  </build>

 

 另一个常用的插件help

http://maven.apache.org/plugins/maven-help-plugin/

 help:describe把一个插件的信息显示出来

# mvn help:describe -DgroupId=org.somewhere -DartifactId=some-plugin -Dversion=0.0.0

 

如:

mvn help:describe -DgroupId=org.apache.maven.plugins -DartifactId=maven-compiler-plugin -Dversion=3.1

或者

pom.xml--右键--Run As --  Maven build -- 在golas输入help:describe -DgroupId=org.apache.maven.plugins -DartifactId=maven-compiler-plugin -Dversion=3.1
 -- Run

输入

[INFO] org.apache.maven.plugins:maven-compiler-plugin:3.1

Name: Maven Compiler Plugin
Description: The Compiler Plugin is used to compile the sources of your
  project.
Group Id: org.apache.maven.plugins
Artifact Id: maven-compiler-plugin
Version: 3.1
Goal Prefix: compiler

This plugin has 3 goals:

compiler:compile
  Description: Compiles application sources

compiler:help
  Description: Display help information on maven-compiler-plugin.
    Call mvn compiler:help -Ddetail=true -Dgoal=<goal-name> to display
    parameter details.

compiler:testCompile
  Description: Compiles application test sources.

For more information, run 'mvn help:describe [...] -Ddetail' 

 

help简化的写法:

http://maven.apache.org/plugins/maven-help-plugin/examples/describe-configuration.html

 help:describe -Dplugin=source

 

sql插件,可以执行sql

http://mojo.codehaus.org/sql-maven-plugin/

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <junit.version>4.10</junit.version>
    <mysql.driver>com.mysql.jdbc.Driver</mysql.driver>
    <mysql.url>jdbc:mysql://localhost:3306/mysql</mysql.url>
    <mysql.username>root</mysql.username>
    <mysql.password>password</mysql.password>
  </properties>

 

	<plugin>
	      	<groupId>org.codehaus.mojo</groupId>
        	<artifactId>sql-maven-plugin</artifactId>
        	<version>1.5</version>
			<dependencies>
				<dependency>
					<groupId>mysql</groupId>
					<artifactId>mysql-connector-java</artifactId>
					<version>5.1.18</version>
				</dependency>
			</dependencies>
			<configuration>
				<driver>${mysql.driver}</driver>
				<url>${mysql.url}</url>
				<username>${mysql.username}</username>
				<password>${mysql.password}</password>
				<sqlCommand>
					create database IF NOT EXISTS maven_test
				</sqlCommand>
			</configuration>
			<executions>
	        	<execution>
	        		<phase>package</phase>
	        		<goals>
	        			<goal>execute</goal>
	        		</goals>
	        	</execution>
	        </executions>
	      	
	      </plugin>

pom.xml--右键--Run As --  Maven build -- 在golas输入clean package 

 

rar插件,可以打rar包

	<plugin>
	      	<groupId>org.apache.maven.plugins</groupId>
        	<artifactId>maven-rar-plugin</artifactId>
        	<version>2.2</version>
        	<executions>
	        	<execution>
	        		<phase>package</phase>
	        		<goals>
	        			<goal>rar</goal>
	        		</goals>
	        	</execution>
	        </executions>
	      </plugin>

 pom.xml--右键--Run As --  Maven build -- 在golas输入clean package

 

参考:

http://www.infoq.com/cn/news/2011/04/xxb-maven-7-plugin

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值