使用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 ...
随机推荐
- scrapy实例:爬取天气、气温等
1.创建项目 scrapy startproject weather # weather是项目名称 scrapy crawl spidername开始运行,程序自动使用start_urls构造Requ ...
- JS基础语法---作用域链
从函数嵌套来分析: (层数一般5层内) var num=10; function f1() { var num=20; function f2() { var num=30; function f3( ...
- SQL 高效运行注意事项(三)
合理配置tempdb 1.tempdb在SQL Server停掉,重启时会自动的drop,re-create. 根据model数据库会默认建立一个新的 2.tempdb对IO的要求比较高,最好分配到高 ...
- RMAN DUPLICATE DATABASE with SET NEWNAME failed: RMAN-05501 RMAN-05517 (Doc ID 387093.1)
RMAN DUPLICATE DATABASE with SET NEWNAME failed: RMAN-05501 RMAN-05517 (Doc ID 387093.1) APPLIES TO: ...
- LInux:YUM源安装工具的配置及使用
YUM源的设置及使用 YUM工具简介 (1)YUM(Yellow dog Upadate Modifie)是改进版的 RPM 管理器,很好地解决了 RPM 软件包的依赖问题. (2)YUM 可以从很多 ...
- deepin,linux服务器,上传下载
------------恢复内容开始------------ 物理机:deepin系统15.11桌面版 服务器:centos7 一.ftp连接服务器 1. deepin默认没有安装命令行的ftp客户端 ...
- LeetCode 307. 区域和检索 - 数组可修改
地址 https://leetcode-cn.com/problems/range-sum-query-mutable/ 题目描述给定一个整数数组 nums,求出数组从索引 i 到 j (i ≤ ...
- poj 3233 矩阵快速幂
地址 http://poj.org/problem?id=3233 大意是n维数组 最多k次方 结果模m的相加和是多少 Given a n × n matrix A and a positive i ...
- Scrum会议(十周)
1.任务分配 2.会议内容探讨了本次取得的重大突破和后续要继续开展的工作.分析了自己在前端开发遇到的问题,以及如何优化自己的前端界面.然后分工,每人都去优化一部分界面,比如段祥负责个人中心的优化,程吉 ...
- 详解C++ STL map 容器
详解C++ STL map 容器 本篇随笔简单讲解一下\(C++STL\)中的\(map\)容器的使用方法和使用技巧. map容器的概念 \(map\)的英语释义是"地图",但\( ...
