maven的命令都是基于插件的,简单的讲一下插件的使用方式:
配置插件的xml如下:
<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>
<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.25</version>
</dependency>
</dependencies>
<configuration>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/user</url>
<username>root</username>
<password>123456</password>
<sqlCommand> create database if not exists maven_test </sqlCommand>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals><goal>execute</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
这个xml配置了2个插件第一个插件是source插件 是用来打包源码的,第二个插件是sql插件,是用来操作数据库的。
讲下第一个插件,首先<plugin>中配置的是插件的地址,
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
插件的执行,他的执行目标是jar-no-fork,然后<phase>package</phase>表示该插件的命令跟在package生命周期的后面,当我们输入mvn package当packag命令执行完后就执行source命令