maven 引用本地jar包

问题描述:

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

解决方案:

  在项目中建立lib包,将需要的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中。

posted @ 2019-04-08 17:05  沙漠旅途  阅读(11423)  评论(1编辑  收藏  举报