Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement springbootweb project in jar or war package and run

Shulou Source: shulou.com Published: 2022-06-03 06:00:42 10月03日 Update

This article mainly introduces "how to achieve springbootweb project jar or war package and run", in daily operation, I believe many people in how to achieve springbootweb project jar or war package and run problems there are doubts, Xiaobian consulted all kinds of information, sorted out simple and easy to use operation methods, hope to answer "how to achieve springbootweb project jar or war package and run" doubts help! Next, please follow the small series to learn together!

(1) Springboot web project jar package

1. Packing

Two packing methods

maven command packaging

Switch directories to project root, where pom.xml is located, and run maven packaging command.

mvn clean package -Dmaven.test.skip=true

IDEA tool performs maven task packaging

xxx-0.0.1-SNAPSHOT.jar will be generated under xxx project module/target directory

2. Run jar package

Start running (switch directory to target, execute command)

F:\Java\idea-workspace\shixun02\web1>cd springboot1F:\Java\idea-workspace\shixun02\web1\springboot1>cd targetF:\Java\idea-workspace\shixun02\web1\springboot1\target>java -jar web1-0.0.1-SNAPSHOT.jar

Note: If you want to set the boot server port yourself when starting the springboot project, the command is as follows: java -jar web1-0.0.1-SNAPSHOT.jar --server.port=8081

(2) Springboot web project war package, independent deployment to tomcat run

Springboot project created using maven, the default is jar package, springboot and tomcat with their own. Now you need to package the project and deploy it to tomcat. Here are the steps:

1. Modify the pom.xml file. Change jar to war.

com.youzhong web1 0.0.1-SNAPSHOT war

2. Set finalName in the build node in the pom.xml file to the path in server.context-path. The name of the project (the name of the package).

org.springframework.boot spring-boot-maven-plugin web1

3. Remove tomcat module from spring-boot-starter-web dependency.

org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat

4. Add servlet dependencies.

javax.servlet javax.servlet-api 3.1.0 provided

5. Create a new startup class. (Requires same level directory as previous startup classes)

public class SpringBootStartApplication extensions SpringBootServletInitializer { @Override protected SpringApplicationBuilder configuration (SpringApplicationBuilder builder) { //Note that this points to the Application startup class return builder.sources(Web1Application.class) originally executed with the main method; }}

Note: Web1Application.class is the default startup class of the project generated by springboot. For example, Web1Application.class is the main startup class with @SpringBootApplication annotation.

6. Packaging with mvn command

mvn clean package -Dmaven.test.skip=true

or

Using maven tasks in IDEA

7. Deploy a copy of the war package to tomcat's webapps directory, launch tomcat and test it.

At this point, the study on "how to achieve springbootweb project jar or war package and run" is over, hoping to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Tags: Project run command directory study task name that is project file method more server module switch help service build utility next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MySQL vpn Redmi Docker