Several ways for Springboot to start maven and gradle projects

How to start maven project

  1. Run the startup class directly
  2. Run with mvn spring-boot:run
  3. After packaging into a jar package, use java -jar xxx.jar to run
  4. After packaging into a war package, use java -jar xxx.war to run

Method 1: Run the startup class directly

Insert picture description here

方式2:mvn spring-boot:run

The pom.xml file of the springboot project contains by default:

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

So you can use the following method to run graphically.
Click on the small window in the lower left corner, and then Mavne Projects will appear on the right
. Find your springboot project in Mavne Projects, and then click spring-boot:run
Insert picture description here
or run with the command line:
first enter springboot Project directory, and then run the mvn spring-boot:run commandInsert picture description here

Pack it into a jar package and run

The default packaging form in the pom.xml file of the springboot project is a jar package

<packaging>jar</packaging>

The packaging method is as follows:

  1. Graphical packaging
    Insert picture description here
  2. Command line packaging
    Enter the springboot project directory, and then run the mvn package command to Insert picture description here
    run the jar package:
    Maven is packaged in the target directory by default, enter the target directory of the springboot project, and then run the java -jar xxx.jar command to run the program.
    Insert picture description here
    Pack it into a war package and run
    Modify the packaging form in the pom.xml file of the springboot project to be a war package
<packaging>war</packaging>

The subsequent packaging method and running method are similar to the packaged jar package operation, the only difference is that the running command is in the form of java -jar xxx.war.

Gradle project startup method

  1. java -jar xxx.jar

  2. Run as "java Application"

  3. gradlew bootRun, run with the version of gradle wrapper;

  4. gradle bootRun, run with the local gradle version.

Guess you like

Origin blog.csdn.net/qq_40093255/article/details/115081686