Spring Boot directly uses jar to run the project, springjar
Overview
The article "Create and run" at the beginning of Spring Boot describes how to create and run a Sprint Boot project. However, the running method is directly Run in IDEA. Another method is to run the Spring Boot program directly in the command line.
Package into jar
In the past, WEB programs had to be packaged into WAR packages and deployed on Tomcat. Spring Boot supports packaging in the form of JAR, which is supported even if the JAR contains images and pages. In addition, the JAR package can be conveniently deployed to Docker.
To package Spring Boot into a JAR file, add the following code to the POM. xml file:
<groupId>com.springboot</groupId><artifactId>study</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging>
Change packaging to jar. You also need a Maven plug-in.
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
You can use the following operations in IDEA to create a JAR package.
Click Maven Projects on the Right of IDEA, and click the red part in the pop-up window to execute the Maven command.
After clicking, the window for executing the Maven command is displayed. Enter
clean package
You can perform the packaging operation.
After successful execution, you can find the corresponding JAR package under the target directory in the project directory.
study-0.0.1-SNAPSHOT.jar
Execute the JAR package
Start a CMD or other command line tool and execute the following command.
java -jar study-0.0.1-SNAPSHOT.jar
Enter
Http: // localhost: 8080/hello
The browser will output
hello,Spring Boot
For specific code, see the previous Spring Boot opening section-create and run.
Summary
The above section describes how to use jar to run the project in Spring Boot. I hope it will be helpful to you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!