1.修改jar为war包形式
<project ······> <modelVersion>4.0.0</modelVersion> <packaging>war</packaging> //指定为war包 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.6.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> ······
2.去除Spring Boot内置Tomcat
将以下代码从pom.xml中删除
<!-- tomcat 依赖包 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
3.增加Tomcat启动插件
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <includeSystemScope>true</includeSystemScope> <fork>true</fork> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> </build>
4.使用maven编译程序
[root@192 TmallDemo-master]# mvn clean install -Dmaven.test.skip=true [root@192 TmallDemo-master]# ll target/ 总用量 447084 drwxr-xr-x. 6 root root 135 10月 17 22:10 classes drwxr-xr-x. 3 root root 25 10月 17 22:10 generated-sources drwxr-xr-x. 2 root root 28 10月 17 22:10 maven-archiver drwxr-xr-x. 3 root root 35 10月 17 22:10 maven-status drwxr-xr-x. 5 root root 80 10月 17 22:10 TmallDemo-0.0.1-SNAPSHOT -rw-r--r--. 1 root root 232534650 10月 17 22:11 TmallDemo-0.0.1-SNAPSHOT.war