问题描述:

  在pom.xml中引入的依赖,在部署时发现在maven仓库中找不到,导致项目部署失败。尤其在自动化部署时(jenkins),通常都是在公司自己搭建的maven库中进行jar下载。缺包的现象不时会发生。

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

解决方案:

  在项目中建立lib包,将需要的jar包放入目录。

 maven 引用本地jar包 随笔

  然后pom.xml中的依赖项,默认是去maven仓库中下载,所以需要指定jar路径。

        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <scope>system</scope>
            <version>1.0</version>
            <systemPath>${basedir}/lib/ojdbc6-11.2.0.1.0.jar</systemPath>
        </dependency>

这样配置后,通过IDE已经可以正常运行。但是springboot项目都是以运行jar包的方式运行,这里并不能将lib打包到jar中。

            <resource>
                <directory>${project.basedir}/lib</directory>
                <targetPath>BOOT-INF/lib/</targetPath>
                <includes>
                    <include>**/*.jar</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <targetPath>BOOT-INF/classes/</targetPath>
            </resource>

如此,便能引入本地包并且打入jar中。

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄