-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SpringBoot系列之—瘦身部署 #41
Labels
Comments
我初步尝试是不行的,你确定是能正常运行的吗 |
@Linda-Tan 我们公司的项目,SpringBoot的工程,都是以这种部署的。 请问,你那边无法运行,具体有报什么错吗? 是编译的时候有问题?还是运行的时候有问题? |
我在windows 环境下 无法正常启动,说找不到loader.path |
@Linda-Tan 我在Windows下测试过,运行是没有问题的.
例如,我将制作好的包,放在 D:\test\ 目录下,运行下面命令 java -Dloader.path=D:\test\lib -jar D:\test\ springboot-jsp-0.0.1-SNAPSHOT.jar |
嗯嗯,用原来的命令提示符(CMD)是可以的,win10 默认用他的Powershell 是不支持的,MS很恶心。谢谢! |
enjoy <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.11.RELEASE</version>
<configuration>
<layout>ZIP</layout>
<includes>
<include>
<groupId>nothing</groupId>
<artifactId>nothing</artifactId>
</include>
</includes>
<attach>false</attach>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.2</version>
<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>
</configuration>
</execution>
</executions>
</plugin> java -Dloader.path=D:\test\lib\ -jar D:\test\ springboot-jsp-0.0.1-SNAPSHOT.jar |
我发现这个并不能在spring cloud 中使用。 有些不要数据源的消费者,也会被加载数据源jar,导致无法启动 |
能问下 你这是什么解压软件吗? |
使用的是 : Dr.unarchiver.app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
一、前言
SpringBoot部署起来虽然简单,如果服务器部署在公司内网,速度还行,但是如果部署在公网(阿里云等云服务器上),部署起来实在头疼: 编译出来的 Jar 包很大,如果工程引入了许多开源组件(SpringCloud等),那就更大了。
这个时候如果想要对线上运行工程有一些微调,则非常痛苦, :(
二、瘦身前的Jar包
Tomcat在部署Web工程的时候,可以进行增量更新,SpringBoot也是可以的~
SpringBoot编译出来的Jar包中,磁盘占用大的,是一些外部依赖库(jar包),例如:
进入项目工程根目录,执行
mvn clean install
命令,得到的Jar包,用压缩软件打开,目录结构如下:整个Jar包 18.18 MB, 但是
BOOT-INF/lib
就占用了将近 18 MB:三、解决方法
POM文件如下:
进入项目根目录,执行命令:
mvn clean install
将编译后的Jar包解压,拷贝
BOOT-INF
目录下的lib
文件夹 到目标路径;配置完成后,再次执行编译:
mvn clean install
生成的 Jar 包体积明显变小,如下所示, 外部的 jar 包已经不会被引入了:
将
步骤1 解压出来的lib文件夹
、步骤2编译的jar包
放在同一个目录, 运行下面命令:备注:
/path/to/
改成实际的路径。最终目录文件结构是:
1、通常,一个工程项目架构确定后,引入的jar包基本上不会变,改变的大部分是业务逻辑;
2、后面如果需要变更业务逻辑,只需要轻量地编译工程,大大提高项目部署的效率。
The text was updated successfully, but these errors were encountered: