Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report