Spring Boot directly uses jar to run the project, springjar

Source: Internet
Author: User

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!

Related Article

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.