The SpringBoot project is packaged and deployed to Nginx [no need to configure Nginx]

0. Pre-knowledge

The projects packaged by springboot are divided into two types jar: andwar

jar package

When a jar type project is packaged with the SpringBoot packaging plug-in, a tomcat jar will be built

So we can use jdk to run directly, and put the function code into its built-in tomcat to run.

war package

When packaging, you need to delete the built-in tomcat plug-in and configure the dependencies of the servlet. Just put the war in the tomcat server and run it normally. 1. Make jar package

1. Import the SpringBoot packaging plugin

pom.xmlAdd the following code in the root directory of the project


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


[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-3ti68bn5-1684575504465)(assets/image-20230520164246-d7xktph.png)]

After the copy is complete, choose to update maven dependencies

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-7834dAox-1684575504466)(assets/image-20230520164257-1sp9idb.png)]

2. Check whether the packaging method is jar

If not, the default is jarpackage mode

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-90VDSmAe-1684575504467)(assets/image-20230520164833-u6wtx9r.png)]

If any, modify to jar

    <packaging>jar</packaging>

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-45CSriYE-1684575504467)(assets/image-20230520164923-ukm3ekc.png)]

3. Packing

Click Maven–> Lifecycle—> on the rightpackage

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-o2tIIybQ-1684575504467)(assets/image-20230520170201-9a5ujm7.png)]

4. Successfully packaged

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-qzi1P0ja-1684575504467)(assets/image-20230520170255-4po7iqf.png)]

Look at the corresponding jar package location

5. Try running on the server

Switch to a location on the server where you want to store the backend jar package, and open the transfer via xftp

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-n7gh0c62-1684575504468)(assets/image-20230520171217-z09so3k.png)]

nohup java -jar springboot.jar &

nohup: no hang up (do not hang up) and save the screen output record to the log file

&: Indicates background startup

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-WyiVXfSt-1684575504468)(assets/image-20230520171652-qkgh9ox.png)]

6. Try the browser to access the corresponding interface

Open implementation log

tail -f nohup.out

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-SsVgLnGJ-1684575504468)(assets/image-20230520171744-m023l8s.png)]

browser access page

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-a2uoGg3Q-1684575504469)(assets/image-20230520171805-ahuv0a6.png)]

Corresponding output log file

[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-voJ74hHr-1684575504469)(assets/image-20230520171822-ryg2lqd.png)]

It doesn't matter here, we just test whether it is connected.

The interfaces for subsequent requests are all accessed through the front end

Guess you like

Origin blog.csdn.net/qq_22841387/article/details/130783990