Two ways to package maven project (war and jar)
1. War package operation method
Put the project into a war package:
####### ① Configure this sentence in pom.xml (this is to control war package or jar package)
<packaging>war</packaging>
In the following build configuration: (This is the name of the control war package)
<build>
<finalName>ROOT</finalName>
………………
</build>
####### ②Application file modification
/**
* 打成war包
*/
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(ApplicationRun.class);
}
####### ③
Add code to the spring-boot-starter-web of the pom file in the pom.xml , remove the embedded tomcat plugin: the first one is recommended
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
or
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
<version>1.2.4.RELEASE</version>
</dependency>
Add code
. The war package is printed in this
way. Running mode: Deploy a tomcat locally (or on linux), upload the war package to webapps, and delete other things under webapps
This exposes the port of tomcat, because the built-in tomcat of springboot is excluded
Then execute the startup command in the bin directory: linux is ./startup.sh
click on startup.bat under the local tomcat
2.jar package running
Remove
<packaging>war</packaging>
Or write
<packaging>jar</packaging>
Tomcat needs to be introduced, and can not be used
<scope>provided</scope>
and the <exclusion>
type is the jar package, and contains tomcat, can run in the dos environment,
put the jar package in the folder, execute in the folder: java -jar + jar package name, so Get up
or hang in the background: nohup java -jar + jar package name &