- 配置文件pom.xml
1
2
3
4
5
6
7
8
9
10
11<packaging>war</packaging>
-----------------------------------完美分割线
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
-----------------------------------完美分割线
<build>
<finalName>testJenkins</finalName>
</build> - application.properties
1
2
3
4
5# context-path 和 pom.xml的build-finalName 一致
server.context-path=/testJenkins
#如果有指定端口,可以去掉。
#server.port=9990 - 编写启动类
1
2
3
4
5
6
7
8
9public class TomcatServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
//Application.class就是springboot的 @SpringBootApplication 类
return application.sources(Application.class);
}
} - 命令打包参考了此文
1
mvn package