One: Hit Jar bag
Add the following dependencies in the Pom.xml of the project
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Our current project is using the packaging method of the jar package command, jar package.
we went into this directory to open this jar package with compression software , where we found a folder called lib , open Lib Folder Discovery This folder is full of project-dependent jar packages, and even Tomcat. This jar package contains a jar package , which we call the Fatjar ( fat jar Package )
since Fatjar itself includes Tomcat, We do not need to deploy it, and we can start our application directly at the command line, in the command line, into the jar The directory where the package resides, we can execute the jar package with the following Java–jar command . The startup information appears in the console and the browser accesses the program
II: Fight the War bag
Spring-boot provides inline tomcat by default , so packaging generates jar packages directly and can be started with the Java-jar command. However, sometimes we prefer a tomcat to manage multiple projects, in which case the project is a war -format package rather than a jar Format of the package.
We follow the steps below to complete the transformation of the project
(1) modify pom.xml
To change the packaging method to War
<packaging>war</packaging>
Add dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Spring-boot-starter-tomcat is the dependency that was passed over, and by default it hits the packet, so we can introduce this dependency again and specify a dependency range of provided, so The Tomcat -related jar will not be packaged in the war .
(2) add servletinitializer
Import Org.springframework.boot.builder.SpringApplicationBuilder;
Import Org.springframework.boot.context.web.SpringBootServletInitializer;
public class Servletinitializer extends Springbootservletinitializer {
@Override
Protected Springapplicationbuilder Configure (springapplicationbuilderapplication) {
Return application.sources (Application.class);
}
}
since we are using the web3.0 specification, there is no Web. Xml , and this class has the same effect as Web. XML .
(3) run the Package Packaging command to generate a war packet
after the build , put the war package into Tomcat, start Tomcat, and test whether the completed feature is ready to use.
Springboot playing jar and war packages