1.修改打包方式爲war
2.添加第三方依賴的jar到pom
<groupId>otc</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/otc-commons-logging-1.2.jar</systemPath>
</dependency>
3.排除內置的Tomcat(以下兩種方式均可)
方式一:添加依賴
<dependency><!--本機運行把scope註釋掉,打包時scope要帶着 -->
<!--打包的時候可以不用包進去,別的設施會提供。事實上該依賴理論上可以參與編譯,測試,運行等週期。
相當於compile,但是打包階段做了exclude操作-->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
方式二:排除spring-boot-starter-web中的Tomcat
<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>
4.添加plugin
<plugin>
<!--<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArguments>
<bootclasspath>${JAVA_HOME}/jre/lib/rt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>src/main/resources/lib</directory>
<targetPath>WEB-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
打成war部署到外部Tomcat需要改變啓動方式
到此springboot攜帶第三方jar包打成war包結束。
不足之處還請指正。