SpringBoot部署的jar包瘦身

pom文件打包插件更换

参考连接:https://www.jb51.net/program/293676eog.htm

参考连接:https://blog.csdn.net/meng_9543/article/details/121329834

复制代码
<build>
        <finalName>xxx-xxx</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <!--换成你自己项目的启动类(path)-->
                    <mainClass>xxx.xxx.xxx.xxxApplication</mainClass>
                    <layout>ZIP</layout>
                    <includes>
                        <!--排除lib包,nothing任何依赖项都不进行打包-->
                        <include>
                            <groupId>nothing</groupId>
                            <artifactId>nothing</artifactId>
                        </include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!--拷贝依赖到jar外面的lib目录-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <type>jar</type>
                            <includeTypes>jar</includeTypes>
                            <includeScope>runtime</includeScope>
                            <!--指定拷贝依赖项存放的目录位置-->
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
复制代码

启动命令

java -Dloader.path=./lib -Dfile.encoding=UTF-8 -jar xxx.jar
# loader.path:  引用的目录(你提取存放依赖的目录位置)

 

posted @   小尼  阅读(65)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
历史上的今天:
2022-11-10 harbor安装成功后,有三个容器一直重启
点击右上角即可分享
微信分享提示