In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to run spring cloud into jar package on Windows or Linux. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Sort out some configurations about how Spring Boot runs in the background. Before introducing the background running configuration, let's review several ways of running Spring Boot applications.
1: application main class running Spring Boot
2: use Maven's Spring Boot plug-in mvn spring-boot:run to run
3: after being packed into a jar package, run it using java-jar
We usually use the first two when we develop, and the third when we deploy. However, when we use java-jar to run, it is not running in the background. Let's sort out how to configure background running for Windows and Linux/Unix respectively.
Windows
Windows is relatively simple, we can directly use this software: AlwaysUp. As shown in the following figure, it is simple, violent and easy to use.
Configuration is very simple, we just need to mvn install the Spring Boot application into a jar package, and then write a java-jar yourapp.jar bat file. Open AlwaysUp again, click the first button on the toolbar, as shown in the following figure, select the bat file written above, and fill in the service name.
After the creation is completed, you can see our configured service in the list. By right-selecting Start xxx, you can launch the application in the background.
Linux/Unix
Let's talk about how to configure it on the server. In fact, there are many ways to implement it, and here are two ways that are easier to use:
Nohup and Shell
This method is mainly implemented by using the nohup command, which is described in detail as follows:
Nohup command
Purpose: run the command without hanging up.
Syntax: nohup Command [Arg... [&] description: the nohup command runs the command specified by the Command parameter and any related Arg parameters, ignoring all SIGHUP signals. Use the nohup command to run the program in the background after logging out. To run the nohup command in the background, add & to the end of the command.
So, we just need to use the nohup java-jar yourapp.jar & command to get yourapp.jar running in the background.
However, for ease of management, we can also write some scripts to start the application through Shell
For example, the following:
Script to shut down the application: stop.sh
{
#! / bin/bash
PID=$ (ps-ef | grep yourapp.jar | grep-v grep | awk'{print $2}')
If [- z "$PID"]
Then
Echo Application is already stopped
Else
Echo kill $PID
Kill $PID
Fi
}
Script to start the application: start.sh
{
#! / bin/bash
Nohup java-jar yourapp.jar-- server.port=8888 &
}
Integrate the shutdown and startup scripts: run.sh, because the shutdown application will be executed first, and then start the application, so it will not cause port conflicts and other problems, so it is suitable for repeated calls in the continuous integration system.
{
#! / bin/bash
Echo stop application
Source stop.sh
Echo start application
Source start.sh
}
System service
What does it mean that Spring Boot's Maven plug-in also provides the ability to build a complete executable program? That is, instead of java-jar, we can run jar directly to execute the program. In this way, we can easily create it as a system service to run in the background. The main steps are as follows:
Add the plug-in to Spring Boot in pom.xml and pay attention to setting the executable configuration
Org.springframework.boot
Spring-boot-maven-plugin
True
After completing the above configuration, package it with mvn install to build an executable jar package
Create a soft connection to the / etc/init.d/ directory
Sudo ln-s / var/yourapp/yourapp.jar / etc/init.d/yourapp
After the soft connection is created, we can control the start, stop and restart operations by applying to the yourapp.jar with the following command
/ etc/init.d/yourapp start | stop | restart
This is the end of the article on "how to run spring cloud into jar package on Windows or Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.