Maven 设置 JDK 编译版本
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<target>1.8</target>
<source>1.8</source>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
Maven 设置 Tomcat 版本
Maven 默认 Tomcat 插件版本是6,可在pom文件中添加Tomcat7插件,在pom.xml中加入:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>9090</port>
<uriEncoding>UTF-8</uriEncoding>
</configuration>
</plugin>
多了一个 tomcat7 插件:
手动输入 tomcat7:run 命令运行项目:
注意:
虽然手动加入了tomcat7插件,但是maven集成的tomcat6还是存在的,并不是覆盖了tomcat6,输入tomcat:run命令运行项目还是通过tomcat6部署的。
使用tomcat6部署jdk1.8编译的项目,会存在无法编译servlet问题。
Maven 设置打包加入源码
配置maven-source-plugin。
<build>
<plugins>
<!-- 打包的时候加入源码 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Maven 打包时执行测试用例插件
如果你执行过mvn test或者执行其他maven命令时跑了测试用例,你就已经用过maven-surefire-plugin了。maven-surefire-plugin是maven里执行测试用例的插件,不显示配置就会用默认配置。这个插件的surefire:test命令会默认绑定maven执行的test阶段。
<!-- 打包的时候跳过测试junit -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
Maven 打包时将依赖的类重命名并打包进来
maven-shade-plugin提供了两大基本功能:
- 将依赖的jar包打包到当前jar包(常规打包是不会将所依赖jar包打进来的);
- 对依赖的jar包进行重命名(用于类的隔离);
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>com.alibaba.fastjson</pattern>
<shadedPattern>shade.com.alibaba.fastjson</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache</pattern>
<shadedPattern>shade.org.apache</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>