Jenkins构建maven项目:无法找到非maven仓库的jar包

        工作中使用jenkins构建maven项目时,会自动从远程maven中央仓库拉取pom.xml需要的jar包,但是有些jar包可能是自己本人集成的或者是maven中央仓库找不到的,这个时候使用jenkins构建项目就会报错。

        jenkins拉取的代码,默认是在jenkins的安装目录下的workspace中,我是用yum安装jenkins的,因此workspace的目录是:/var/lib/jenkins/workspace

解决方案:

我项目的结构为:

 将包放在指定的位置,然后在pom.xml中指定包的位置,我是把依赖放在项目中创建的lib文件夹下 

scope一定得是system,这样就能找到本地的jar包了。

但是还有一个问题,就是你本地启动没问题,然后打包放到服务器上就发现启动报错,我仔细看了一下,发现是项目达成的jar包中并没有该依赖。因此还需要在pom.xml的<build>中加入一下配置即可:

<resources>
            <resource>
                <directory>${project.basedir}/src/main/resources/lib</directory>
                <targetPath>BOOT-INF/lib/</targetPath>
                <includes>
                    <include>*.jar</include>
                </includes>
            </resource>
            <resource>
                <directory>${project.basedir}/src/main/java</directory>
                <targetPath>BOOT-INF/classes/</targetPath>
                <includes>
                    <include>cc</include>
                </includes>
            </resource>
            <resource>
                <directory>${project.basedir}/src/main/resources</directory>
                <targetPath>BOOT-INF/classes/</targetPath>
                <includes>
                    <include>*</include>
                </includes>
            </resource>
        </resources>
发布了69 篇原创文章 · 获赞 35 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/xiaoye319/article/details/101512061