最近负责一个纯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项目打包的更多相关文章

  1. [Maven] - Eclipse "maven compiler plugin" 冲突解决

    刚安装最新的Maven 3.2.5,在eclipse中使用maven的Run As->Maven Install,总会提示: Failed to execute goal org.apache. ...

  2. [Apache Maven Shade Plugin] [example] [001] 官方例子:includes-excludes

    链接地址:[Selecting Contents for Uber JAR](http://maven.apache.org/plugins/maven-shade-plugin/examples/i ...

  3. 施用 maven shade plugin 解决 jar 或类的多版本冲突

    施用 maven shade plugin 解决 jar 或类的多版本冲突   使用 maven shade plugin 解决 jar 或类的多版本冲突java 应用经常会碰到的依赖的三方库出现版本 ...

  4. Maven - 深入理解maven构建生命周期和各种plugin插件

    作者:亚当-adam 来源:CSDN 原文:https://blog.csdn.net/zhaojianting/article/details/80321488 版权声明:本文为博主原创文章,转载请 ...

  5. java maven compiler设置默认1.8

    方法一: <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupI ...

  6. maven maven.compiler.source和maven.compiler.target的坑

    最近建议产品组把jdk 1.7升级到1.8,昨晚开发报了个问题过来,说maven.compiler.source和maven.compiler.target改成1.8之后,编译出来的代码还是1.7,如 ...

  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 ...

  8. Maven学习笔记-02-Maven项目打包配置与测试

    一 Maven项目打包配置 1 为整个项目统一指定字符集 <properties> <project.build.sourceEncoding>UTF-</project ...

  9. maven 把spring项目打包成可执行的文件

    转载自http://www.mamicod.e.com/info-detail-635726.html 最近需要解决Maven项目导入可执行的jar包的问题,如果项目不包含Spring,那么使用mvn ...

  10. maven项目打包额外lib目录

    maven项目依赖了几个额外的jar包一直都无法打进最终jar,不知道哪里出了问题.一直对这块不甚清楚,就大概梳理一下 默认打包方式: maven项目下,默认编译目录为 src/main/java和s ...

随机推荐

  1. 看完这篇文章,我奶奶都知道什么是JVM中的内存模型与垃圾回收!

    扩展阅读:JVM从入门开始深入每一个底层细节 六.内存模型 6.1.内存模型与运行时数据区 Java虚拟机在执行Java程序的过程中会把它所管理的内存划分为若干不同数据区域. Java内存模型的主要目 ...

  2. WORD 和Uint16的区别

    UINT   A 16-bit unsigned integer on Windows versions 3.0 and 3.1; a 32-bit unsigned integer on Win32 ...

  3. python虚拟环境virtualenv下安装MySQL-python(1.2.3)

    该文章很有用建议收藏 我们在Windows下开发python应用时,可能需要安装各种第三方模块,但如果又不想污染公共的python环境,怎么办呢?最好是在各自的 python工程中创建一个virtua ...

  4. Linux—文件管理

    文件操作 创建文件 [root@localhost ~]# touch a.txt # 创建单个文件 [root@localhost ~]# touch b.txt c.txt # 创建多个文件 删除 ...

  5. xshell连接console口

  6. 操作系统|VirtualBox for Mac(虚拟机软件)

    VirtualBox是德国一家软件公司InnoTek所开发的虚拟系统软件,它不仅具有丰富的特色,而且性能也很优异,更是开源的,成为了一个发布在GPL许可之下的自由软件.VirtualBox 可以在 L ...

  7. python保护变量(_),私有变量(__),私有方法,

    上图为常规代码 私有变量(__),私有方法:只是解释器换名字了,可以通过方法/实例字典发现改后的名字: 保护变量,解释器不做任何处理:只是开发者约定的,尽量不要改动: 此时实例无法修改__age属性值 ...

  8. requests乱码问题

    有三种方法解决请求后乱码问题. 一:获取二进制数据,再利用str进行编码转换 url='http://music.baidu.com' r = requests.get(url) html=r.con ...

  9. Scrum会议(十周)

    1.任务分配 2.会议内容探讨了本次取得的重大突破和后续要继续开展的工作.分析了自己在前端开发遇到的问题,以及如何优化自己的前端界面.然后分工,每人都去优化一部分界面,比如段祥负责个人中心的优化,程吉 ...

  10. 乘积量化(Product Quantization)

    乘积量化 1.简介 乘积量化(PQ)算法是和VLAD算法是由法国INRIA实验室一同提出来的,为的是加快图像的检索速度,所以它是一种检索算法,在矢量量化(Vector Quantization,VQ) ...