Maven 之编译、Tomcat等常用插件

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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值