spring boot打包为war包,引入外部jar包

1,在src/main/resource下新建目录jar,将外部jar包放在该目录下

 2,在pom.xml中添加依赖

 groupId,artifactId,version可随便写

<dependency>
            <groupId>com.huawei</groupId>
            <artifactId>gsjdbc4</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${basedir}/src/main/resources/jar/gsjdbc4.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.huawei</groupId>
            <artifactId>gsjdbc200</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${basedir}/src/main/resources/jar/gsjdbc200.jar</systemPath>
        </dependency>

此时,本地启动项目访问是没有问题的,但是打包的话就会报错,需要以下步骤

3,pom.xml中增加plugin配置

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>src/main/resources/jar/</directory>
                            <targetPath>WEB-INF/lib/</targetPath>
                            <includes>
                                <include>**/*.jar</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>

然后再打包即可

4,遇到的问题

打包时报错: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)

原因: maven 插件 maven-war-plugin 中 Servlet 版本太低,要求必须要有web.xml文件才行

解决方法: 把plugin配置里面的<version>2.4</version>去掉,再次打包即可

猜你喜欢

转载自www.cnblogs.com/cailijuan/p/11934444.html