How to deploy the springboot project in maven to the linux server, mavenspringboot

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.