使用maven-compiler-plugin以及maven-shade-plugin完成maven项目打包
最近负责一个纯maven项目(项目需求尽量轻量化),需要自己完成打包工作.
因此,基于maven-compiler-plugin以及maven-shade-plugin完成项目的打包工作.
其中:
maven-compiler-plugin负责项目编译;maven-shade-plugin负责最终的打包操作.
以下所示操作,均在pom.xml文件中进行.
项目基本属性
<groupId>com.test</groupId>
<artifactId>app</artifactId> //
<version>0.1.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
添加插件
<build>
<plugins>
<!-- 编译java项目-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<!-- 创建一个fat jar,包含所有必须的依赖 -->
<!-- 根据自己的main函数替换<mainClass>...</mainClass>中的配置 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<!-- 指定不需要打包的文件(可以使用通配符) -->
<excludes>
<exclude>org.apache.flink:force-shading</exclude>
<exclude>com.google.code.findbugs:jsr305</exclude>
<exclude>org.slf4j:*</exclude>
<exclude>log4j:*</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<!-- Do not copy the signatures in the META-INF folder.
Otherwise, this might cause SecurityExceptions when using the JAR. -->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.test.app.Application</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Tips:
maven-shade-plugin比较强大,还可以解决打包文件中的依赖冲突,读者可以自行寻找相关文章.
PS:
如果您觉得我的文章对您有帮助,请关注我的微信公众号,谢谢!
使用maven-compiler-plugin以及maven-shade-plugin完成maven项目打包的更多相关文章
- [Maven] - Eclipse "maven compiler plugin" 冲突解决
刚安装最新的Maven 3.2.5,在eclipse中使用maven的Run As->Maven Install,总会提示: Failed to execute goal org.apache. ...
- [Apache Maven Shade Plugin] [example] [001] 官方例子:includes-excludes
链接地址:[Selecting Contents for Uber JAR](http://maven.apache.org/plugins/maven-shade-plugin/examples/i ...
- 施用 maven shade plugin 解决 jar 或类的多版本冲突
施用 maven shade plugin 解决 jar 或类的多版本冲突 使用 maven shade plugin 解决 jar 或类的多版本冲突java 应用经常会碰到的依赖的三方库出现版本 ...
- Maven - 深入理解maven构建生命周期和各种plugin插件
作者:亚当-adam 来源:CSDN 原文:https://blog.csdn.net/zhaojianting/article/details/80321488 版权声明:本文为博主原创文章,转载请 ...
- java maven compiler设置默认1.8
方法一: <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupI ...
- maven maven.compiler.source和maven.compiler.target的坑
最近建议产品组把jdk 1.7升级到1.8,昨晚开发报了个问题过来,说maven.compiler.source和maven.compiler.target改成1.8之后,编译出来的代码还是1.7,如 ...
- 【maven】maven的web项目打包报错:No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK
打包过程中报错如下: No compiler is provided in this environment. Perhaps you are running on a JRE rather than ...
- Maven学习笔记-02-Maven项目打包配置与测试
一 Maven项目打包配置 1 为整个项目统一指定字符集 <properties> <project.build.sourceEncoding>UTF-</project ...
- maven 把spring项目打包成可执行的文件
转载自http://www.mamicod.e.com/info-detail-635726.html 最近需要解决Maven项目导入可执行的jar包的问题,如果项目不包含Spring,那么使用mvn ...
- maven项目打包额外lib目录
maven项目依赖了几个额外的jar包一直都无法打进最终jar,不知道哪里出了问题.一直对这块不甚清楚,就大概梳理一下 默认打包方式: maven项目下,默认编译目录为 src/main/java和s ...
随机推荐
- .Net Core MVC中过滤器简介
在.Net Framework MVC 中有四种过滤器,授权过滤器(Authorize).Action 过滤器.结果过滤器(Result).异常过滤器(Exception)四种过滤器.在.Net Co ...
- angularjs路由传值$routeParams
AngularJS利用路由传值, 1.导包 <script src="angular.min.js"></script> <script src=&q ...
- python2 和 python3共存的常见使用(如安装虚拟环境的问题)
1.安装好python2和python3,配置好全部环境变量 环境变量修改后,需要重新启动命令行才有效 2.如何启动不同版本的python 启动的时候会执行python.exe,python2和pyt ...
- MySQL 优化 (四)
参数优化 innodb_log_buffer_size 此参数确定些日志文件所用的内存大小,以M为单位.缓冲区更大能提高性能,对于较大的事务,可以增大缓存大小. innodb_log_buffer_s ...
- 如何使用块更改跟踪文件估算RMAN增量备份大小 (Doc ID 1938079.1)
How to estimate RMAN incremental backup size using block change tracking file (Doc ID 1938079.1) APP ...
- [Go] 时序数据库influxdb的安装
日志类的数据时候存储在时序数据库中,下面就是时序数据库influxdb的安装 curl -sL https://repos.influxdata.com/influxdb.key | apt-key ...
- apache配置文件说明及一些指令
httpd命令和apachectl命令 [root@localhost ~]# httpd -h Usage: httpd [-D name] [-d directory] [-f file] [-C ...
- flask中的endpoint、自定义转化器、与djnago中session区别、利用装饰器实现登录认证
flask路由中的endpoint 与自定义转化器 ''' endpoint主要用于 反向解析, 例如:login函数中配的路由是/login,其中endpoint='lg' 则在其他函数,可以用 u ...
- vue-cil3 运行报错
warnings potentially fixable with the `--fix` option. 将一下部分:"lint": "vue-cli-service ...
- redhat 安装 oracle中途遇到的问题(1)
(1)安装到68%时出现弹出框 Error in invoking target 'install' of makefile '/home/oracle/app/oracle/product/11.2 ...
