1、测试插件
maven-surefire-plugin 是maven里执行测试用例的插件,不显示配置就会用默认配置。这个插件的 surefire:test 命令会默认绑定maven执行的 test 阶段。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.19</version>
</dependency>
</dependencies>
<configuration>
<skipTests>true</skipTests>//跳过测试用例
</configuration>
</plugin>
2、编译插件
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>//源代码编译版本
<target>1.6</target>//目标平台编译版本
<includes>
<include>**/*.java</include>
</includes>
<encoding>${project.build.sourceEncoding}</encoding>//字符集编码,这里引用全局属性
</configuration>
</plugin>
3、打包插件 jar
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.picc.StartMain</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
依赖的jar包完全需要被添加进MANIFEST.MF(jar包解压缩后:jar包名/META-INF/MANIFEST.MF)的Class-Path。如果不添加 manifest,最终jar包运行时只要依赖其他jar包就会报错
3、打包插件:war
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<warName>ermss</warName>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<excludes>
<exclude>**/*.jpg</exclude>
</excludes>
</resource>
</webResources>
</configuration>
</plugin>
4、依赖插件:copy依赖jar包
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- 为内置变量,缺省为project.build.directory为Maven内置变量,缺省为target−−>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<!-- 表示是否不包含间接依赖的包 -->
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<!-- 表示复制的jar文件去掉版本信息 -->
<stripVersion>false</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
5、配置文件放在jar包外面:
(1)打包时忽略配置文件‘
(2)复制配置文件到指定目录下
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>*.properties</exclude>
<exclude>*.xml</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<excludes>
<exclude>**/*.properties</exclude>
<exclude>**/*.xml</exclude>
<exclude>*.properties</exclude>
<exclude>*.xml</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<!-- 将本工程例外文件copy至指定路径下 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<!-- <encoding>UTF-8</encoding> -->
<!-- 指定文件输出路径,会将原始路径及其文件全部copy -->
<outputDirectory>${project.build.directory}/conf</outputDirectory>
<resources>
<resource>
<targetPath>${project_loc}</targetPath>
<directory>src/main/resources</directory>
<!-- 将需要copy的配置文件配置到<include></include>标签内。 -->
<includes>
<!-- <include>dubbo.properties</include> -->
<!-- <include>dataSource.properties</include> -->
<!-- <include>dubbo/**</include> -->
<include>**/**</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>