How to deploy the springboot project in maven to the linux server, mavenspringboot
Suppose we already have something
1. maven has been installed
2. The springboot project has been established and can run properly locally.
3. the linux server has the corresponding environment, such as java and mysql.
Next, we can migrate the project to the server for release.
Use maven to package a project and generate a jar File
First, add the following content to our pom. xml file:
org.springframework.boot
spring-boot-maven-plugin
repackage
org.apache.maven.plugins
maven-jar-plugin
true
com.dazhi.Application
This is used to package the configuration of the project, and then run it in the root directory of the project:
mvn package
You will find that A. jar file is generated under the target/folder.
The name of the jar package is the same as that configured in pom. xml.
Upload to server
Next, there are many methods to upload the jar package to the server. The simplest method is to use the tool, the mobaxterm I use,
Find the execution directory and upload and visualize the file.
Run the project on the server
When the location of the jar package is reached, execute:
Java-jar package name. jar
Visit the browser and find that you can
Run the project on the server background and output logs to the specified file
The above running mode is directly executed in the front-end window. When the window is closed, the Service stops. Obviously, the log does not meet our requirements and is directly output to the front-end, no. View post-processing information
Run the following command in the background of the project and output logs to the specified file:
nohup java -jar /usr/webapp/web.jar >/logs/web.log &
What if we want to stop the service?
job
The job command can view the processes running in the background. After seeing the code
kill %num
You can stop a process named num ~, OK.
Write fixed commands to shell scripts to avoid repeated input.
To facilitate every update and deployment, we create a new. sh file and save our commands. It is fine to run the shell script whenever necessary.
Run the following commands in sequence:
touch execute.shvim execute.sh
Write the command to be executed in execute. sh, save and exit, and run
source execute.sh
OK