springboot打成war包并携带第三方jar包

1.修改打包方式为war

    <packaging>war</packaging>

2.添加第三方依赖的jar到pom

    我的第三方jar包在resoueces目录下的lib下(目录可以是其他路径,pom引包要正确)
    <dependency>
    <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>

到此springboot携带第三方jar包打成war包结束。

不足之处还请指正。

猜你喜欢

转载自www.cnblogs.com/wlv1314/p/12127887.html