使用普通的 spring mvn 命令,我可以从命令行启动 spring boot 应用程序并使用 Control+c 终止它。不过,我已经创建了一堆服务,稍后我将对其进行 dockerize。现在它们是由 mvn 生成的普通 java jar 文件。如何使用python脚本或Bash脚本将它们一一启动,然后使用脚本终止它们。有什么方法可以启动它并且脚本不会阻止并且应用程序将有一个我稍后可以用来停止应用程序的名称?
最佳答案
我会遵循 documentation将 Spring-Boot 应用程序安装为 Unix/Linux 服务。
您所要做的就是将此依赖项添加到您的 pom.xml
中:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
添加插件后,您应该安装并创建一个指向您的应用程序的符号链接(symbolic link) ( exact part of documentation ):
Assuming that you have a Spring Boot application installed in
/var/myapp
, to install a Spring Boot application as an init.d service simply create a symlink:
$ sudo ln -s /var/myapp/myapp.jar /etc/init.d/myapp
Once installed, you can start and stop the service in the usual way. For example, on a Debian based system:
$ service myapp start
然后您就可以创建一个 bash 脚本来以干净的方式启动
、停止
或重新启动
您的应用程序。
关于java - 从脚本启动 Spring boot 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41927377/