如何在生产环境中运行spring boot可执行jar? [英] How do I run a spring boot executable jar in a Production environment?

查看:1542
本文介绍了如何在生产环境中运行spring boot可执行jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring boot的首选部署方法是通过一个包含tomcat的可执行jar文件。

Spring boot's preferred deployment method is via a executable jar file which contains tomcat inside.

它以一个简单的 java -jar myapp启动.jar

现在,我想将这个jar部署到我在EC2上的linux服务器上,我错过了什么或者我真的需要创建一个init脚本以正确启动应用程序作为守护进程?

Now, I want to deploy that jar to my linux server on EC2, am I missing something or do I really need to create a init script to properly start the application as a daemon?

如果我只是调用 java -jar 应用程序我退出时就死了。

If I simply call java -jar the application dies when I log out.

我可以在屏幕或nohup中启动它,但这不是很优雅,在我的服务器重启将迫使我登录并启动手动处理。

I could start it in screen or nohup but that is not very elegant and a restart in my server would force me to log in and start the process manually.

那么,Spring boot中的任务是否已经存在?

So, is there something already for the task in spring boot?

推荐答案

请注意,自Spring Boot 1.3.0.M1以来,您可以使用maven和gradle构建完全可执行的jar。

Please note that since Spring Boot 1.3.0.M1, you are able to build fully executable jars using maven and gradle.

对于maven,只需在pom.xml中包含以下内容

For maven, just include the following in your pom.xml

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

对于gradle,将以下代码段添加到build.gradle

For gradle add the following snippet to your build.gradle

springBoot {
    executable = true
}

这些完全可执行的jar包含文件前面的额外脚本,允许您将spring boot jar符号链接到init.d或使用systemd脚本

These fully executable jars contains an extra script at the front of the file, which allows you to just symlink your spring boot jar to init.d or use a systemd script

init.d示例:

$ln -s /var/yourapp/yourapp.jar /etc/init.d/yourapp

这使您可以启动,停止和重启您的应用程序,如:

This allows you to start, stop and restart your application like:

$/etc/init.d/yourapp start|stop|restart

或使用系统脚本

[Unit]
Description=yourapp
After=syslog.target

[Service]
ExecStart=/var/yourapp/yourapp.jar

[Install]
WantedBy=multi-user.target

以下链接的更多信息:
< a href =http:// d ocs.spring.io/spring-boot/docs/1.3.0.BUILD-SNAPSHOT/reference/htmlsingle/#deployment-service\">http://docs.spring.io/spring-boot/docs/1.3.0。 BUILD-SNAPSHOT / reference / htmlsingle /#deployment-service

More informations at the following link: http://docs.spring.io/spring-boot/docs/1.3.0.BUILD-SNAPSHOT/reference/htmlsingle/#deployment-service

这篇关于如何在生产环境中运行spring boot可执行jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆