您的位置:首页 > 其它

在 Jenkins 中,使用 maven 打包报 package xxx does not exist 问题的解决方法

2017-06-21 17:02 555 查看

1 发现问题

今天打算使用 Jenkins 给一些旧项目打包,编译时报以下错误:

...
[ERROR] /var/lib/jenkins/workspace/fsti-pipe/src/main/java/com/fsti/oss/service/sys/PagerService.java:[6,52] package org.springframework.beans.factory.annotation does not exist
...


看日志,直接原因是 spring 的 某些 jar 包不存在!

2 寻找原因

在本地开发环境下,用 idea 的 maven 搭建了与 Jenkins 相同的 maven 环境(启用了新的本地仓库、使用相同版本的 maven-compiler-plugin),可以正常编译!这说明一定是其他原因造成的。

在 Jenkins 中,打开对应项目的【配置】链接,然后点击【构建】页签,在 Goals 中为 Maven 加入
-e -X
参数,并保存:



这样会让 Maven 在构建时打印出更详细的日志。

现在项目再重新构建一次,再看看输出的日志。

配置的仓库已经被使用咯,说明仓库的配置没有问题:

[DEBUG] Using mirror nexus (http://xxx:8383/nexus/content/groups/public/) for snapshots (http://xxx:8081/nexus/content/repositories/snapshots).
...
[DEBUG] Repositories (dependencies): [nexus-all (http://xxx:8081/nexus/content/groups/public, default, releases+snapshots), nexus (http://xxx:8383/nexus/content/groups/public/, default, releases+snapshots)]
...


jdk 打包时引用的依赖包路径有问题,居然会是
/xxx/D:\Program Files\apache-maven\repo...
格式的,这很明显不是 linux 的正确路径嘛:

[DEBUG] -d /var/lib/jenkins/workspace/fsti-pipe/target/classes -classpath /var/lib/jenkins/workspace/fsti-pipe/target/classes:/var/lib/jenkins/workspace/fsti-pipe/D:\Program Files\apache-maven\repo/com/fsti/agile/fsti-agile/1.1.1/fsti-agile-1.1.1.jar:
...


至此可以确定是 maven 的 setting.xml 里面的 localRepository 配置路径的不对,造成了上述问题。一看果然是这样:

3 解决问题

把 maven 的 setting.xml 的 localRepository 改为正确的配置路径即可!记住这个路径在 linux 中必须有读写权限的哦 O(∩_∩)O~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐