首页 > 其他分享 >使用Maven-shade-plugin打包SpringBoot项目

使用Maven-shade-plugin打包SpringBoot项目

时间:2023-04-22 18:44:26浏览次数:53  
标签:SpringBoot plugin spring boot Maven META org INF

使用Maven-shade-plugin打包SpringBoot项目

另附参考文章:https://blog.csdn.net/u011441473/article/details/127844885

好奇葩的打包之旅,最后在stack overflow上找到了解决办法,遇到问题,还是多去google吧,国内真不行,百度质量太低,一件很小的事,花了我1个多小时。。

下面说一下我遇到的奇葩问题:
1.常见的就是mainClass找不到嘛,或者不能将所有包都导入
2.jar包中的配置文件死活不生效(就这个搞了很久),明明jar包根目录配置文件在哪里好好的放着,死活不生效,现在也不知道问题出在哪0.0)
3.Reactive的某个Bean找不到(因为我的demo是用的webFlux+Security)
4.AutoConfiguration不生效(这个也是要吐槽一下的,说什么spring.factories文件找不到,我TM的,明明在jar包里面好好放着。。。)

以上这些问题都可以通过下面的打包方式来解决:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>xxx</groupId>
    <artifactId>xxx</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.8.9</version>
        </dependency>


        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>RELEASE</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    <!--用来管理依赖包的版本-->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.6.7</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.9.0</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>


            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <dependencies>
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <version>2.6.7</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
                    <createDependencyReducedPom>true</createDependencyReducedPom>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.handlers</resource>
                                </transformer>
                                <transformer
                                        implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
                                    <resource>META-INF/spring.factories</resource>
                                </transformer>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.schemas</resource>
                                </transformer>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <!-- 主类 -->
                                    <mainClass>com.xxx.Application</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

    </build>
</project>

标签:SpringBoot,plugin,spring,boot,Maven,META,org,INF
From: https://www.cnblogs.com/zolmk/p/17343675.html

相关文章

  • Springboot 多实例负载均衡部署
    Springboot多实例负载均衡部署一、测试代码:控制层测试代码:importjava.net.Inet4Address;importjava.net.InetAddress;importjava.net.UnknownHostException;@Controller@RequestMapping("/test")publicclassTestController{@GetMapping("")@Resp......
  • SpringBoot+Mybatis这个bug估计连作为神仙的您也无法解决--》Invalid bound statement
    最近开发一个调查单的应用系统,加班加点为了解决几个bug,但是最近两天卡在一个bug上。作为一头牛,不能轻易放弃,向困难挑战是牛的精神。1、Invalidbound问题展示首先,我针对题型QuestionType功能,写了五个子功能:增加题型,删除题型,修改题型,查询单条题型,模糊查询多条记录;还写了问题、调查......
  • SpringBoot文件上传
    application.yml配置spring:#文件上传配置servlet:multipart:max-file-size:10MBmax-request-size:10MBweb:resources:static-locations:/upload/代码packagecom.haoyang.Controller;importorg.springframework.web.bind.a......
  • SpringBoot+Mybatis-Plus+EasyExcel
    首先建立一个springboot项目,导入依赖<!--MyBatisPlus依赖--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.4.2</version......
  • 【maven】模块化开发
    什么是maven模块化开发? 在多人协同开发,特别是规模较大的项目,为了方便日后的代码维护和管理,我们会将每个开发人员的工作细分到具体的功能和模块上。......
  • Pinia持久化失效pinia-plugin-persistedstate
    肯定能解决,哈哈哈,找了这么多,你这次你找对了文章。网络上的这个资料都是有问题的,没有讲明白原由。需求,我想在我前端的业务层里使用store,但是是持久层store,不过没有生效。下面是错误的写法,这个写是不生效的。import{useGlobalStore}from'@/store/modules/global';import......
  • springboot+bootstraptable
    springboot+bootstraptable项目采用的是springboot+bootstraptable搭建的demo  https://blog.csdn.net/weixin_43373818/article/details/114714016基础的增删改查已经实现html页面<!DOCTYPEhtml><htmllang="zh-CN"xmlns:th="http://www.thymeleaf.org"><......
  • Springboot 使用nacos鉴权的简单步骤
    Springboot使用nacos鉴权的简单步骤背景前端时间nacos爆出了漏洞.因为他的默认token固定,容易被利用.具体的问题为:QVD-2023-6271漏洞描述:开源服务管理平台Nacos中存在身份认证绕过漏洞,在默认配置下未token.secret.key进行修改,导致远程攻击者可以绕过密钥认证进入......
  • redis springboot
    【springboot进阶】SpringBoot整合RedisTemplate配置多个redis库RedisTemplate及4种序列化方式  springboot笔记 ......
  • 2、Pipeline语法及使用自定义工具的Maven工程
    Pipeline语法声明式pipeline的结构pipeline的定义有一个明确的、必须遵循的结构,它由一些directive(指令)和section(配置段)组成,每一个section又可包含其它的section、directive和step(执行步骤),以及一些condition(执行条件)的定义;◼Section:用于将那些在某个时间点需要一同运行的条目(i......