Spring boot部署发布到linux

本文介绍如何使用Maven或Gradle将Spring Boot应用打包为可执行的JAR文件,并部署到Linux环境中作为服务运行。文中详细解释了从打包到发布的全过程,并提供了一些技巧,如将JAR文件包装为shell可执行文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

限制条件:

The default script supports most Linux distributions and is tested on CentOS and Ubuntu. Other platforms, such as OS X and FreeBSD, will require the use of a custom embeddedLaunchScript.
当前文档适用于 CentOS and Ubuntu,其他平台需要定制脚本,见参考文档1

1、部署发布

1.1 打包

maven打包成执行文件

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <executable>true</executable>
    </configuration>
</plugin>

 

Gradle设置

springBoot {
    executable = true
}
 
You can then run your application by typing ./my-application.jar (where my-application is the name of your artifact).
打包完成后,可以使用./my-application.jar 运行
 

1.2 原理

linux下查看文件格式为一个bshell可执行文件

[root@i-2cjt6k6n ~]# file audit-console-1.0.0.jar
audit-console-1.0.0.jar: Bourne-Again shell script text executable

 

查看文件内容

vi  audit-console-1.0.0.jar

文件开头:

image

shell与执行jar内容的分割:

image

可以看到,非常高的技巧,jar包包装为shell可执行文件,另外可以加载自己运行

 

1.3 发布为一个服务

 

ln -s /var/myapp/myapp.jar /etc/init.d/myapp
service myapp start
 
更详细的文档见参考文档1

2、参考文档

1、 Installing Spring Boot applications http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/ 

2、 Spring Boot 部署与服务配置  http://blog.youkuaiyun.com/catoop/article/details/50588851

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小小她爹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值