前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Springboot打包 依赖包到单独文件夹

Springboot打包 依赖包到单独文件夹

作者头像
I Teach You 我教你
发布2023-07-18 18:05:33
1.1K0
发布2023-07-18 18:05:33
举报
文章被收录于专栏:王二麻子IT技术交流园地

在使用Springboot开发项目时,打包好的jar包是可以直接运行的,但是通常情况下,这个jar都会很大,因为它默认打包了所有的依赖jar包。此时,就可以通过maven-dependency-plugin插件将依赖包复制到独立的文件夹,在启动jar包的时候引用即可。

代码语言:javascript
复制
<build>
        <finalName>iteachyou-cms</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>cn.xuexiluxian.open.admin.OpenDeerApplication</mainClass>
                    <layout>ZIP</layout>
                    <includes>
                        <include>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>${project.artifactId}</artifactId>
                        </include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>open-deer</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <type>jar</type>
                            <includeTypes>jar</includeTypes>
                            <includeScope>runtime</includeScope>
                            <outputDirectory>${project.build.directory}/libs</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
        </plugins>
    </build>
配置说明
  1. cn.xuexiluxian.open.admin.OpenDeerApplication用于指定该jar包启动时的主类(建议加上)
  2. 加上自己项目的groupId和artifactId即可
  3. open-deer值自定义
  4. ${project.build.directory}/libs依赖包输出目录
  5. 其它写死
启用项目
代码语言:javascript
复制
java -Dloader.path=libs包全路径 -jar open-deer.jar

代码语言:javascript
复制
java -Dloader.path=libs/ -jar open-deer.jar
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022/08/11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 启用项目
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档