Maven无法从Project Repository中找到jar

时间:2016-07-09 11:02:30

标签: java eclipse maven

我有一个jar文件,我需要包含在我的项目中。 我正在和Maven一起使用eclipse

我在计算机上的项目中创建了以下文件夹:

/home/robert/eclipse/BobProjects/BobDiary/in_project_maven_repository/metcarob.com.lib/nachocalendar/0.23

我在那里放了一个名为:

的文件
nachocalendar-0.23.jar

然后我将依赖性添加到我的POM文件中:

<dependency>
  <groupId>metcarob.com.lib</groupId>
  <artifactId>nachocalendar</artifactId>
  <version>0.23</version>
  <scope>compile</scope>
</dependency>

我还将Repo添加到我的pom文件中:

    <repository>
      <id>in-project</id>
      <name>In Project Repo</name>
      <url>file:///home/robert/eclipse/BobProjects/BobDiary/in_project_maven_repository</url>
    </repository>

从我的理解,这应该工作。 当我右键单击我的项目时选择run as和maven install我得到以下错误:

[ERROR] Failed to execute goal on project BobDiary: Could not resolve dependencies for project metcarob.com.BobDiary:BobDiary:jar:0.0.1-SNAPSHOT: Failure to find metcarob.com.lib:nachocalendar:jar:0.23 in file:///home/robert/eclipse/BobProjects/BobDiary/in_project_maven_repository was cached in the local repository, resolution will not be reattempted until the update interval of in-project has elapsed or updates are forced -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project BobDiary: Could not resolve dependencies for project metcarob.com.BobDiary:BobDiary:jar:0.0.1-SNAPSHOT: Failure to find metcarob.com.lib:nachocalendar:jar:0.23 in file:///home/robert/eclipse/BobProjects/BobDiary/

我已经按照我可以看到的所有步骤来创建项目存储库,但它似乎仍然无法找到该文件。

有谁知道我失踪的一步?

由于 罗伯特

更新: 我一定犯过多次错误。 Akber发现了我的第一个错误: 我更改了文件夹,因此组ID位于单独的文件夹中: (metcarob.com.lib现在是metcarob.com.lib)jar文件现在位于: /home/robert/eclipse/BobProjects/BobDiary/in_project_maven_repository/metcarob/com/lib/nachocalendar/0.23

我已经验证了这一点,因为我的机器中存在以下目录: 〜/ .m2目录/库/ metcarob / COM / LIB / nachocalendar / 0.23

我已移动文件,重新启动eclipse并重新运行maven clean和maven install。

现在出现错误:

[ERROR] Failed to execute goal on project BobDiary: Could not resolve dependencies for project metcarob.com.BobDiary:BobDiary:jar:0.0.1-SNAPSHOT: Failure to find metcarob.com.lib:nachocalendar:jar:0.23 in file:///home/robert/eclipse/BobProjects/BobDiary/in_project_maven_repository was cached in the local repository, resolution will not be reattempted until the update interval of in-project has elapsed or updates are forced -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project BobDiary: Could not resolve dependencies for project metcarob.com.BobDiary:BobDiary:jar:0.0.1-SNAPSHOT: Failure to find metcarob.com.lib:nachocalendar:jar:0.23 in file:///home/robert/eclipse/BobProjects/BobDiary/in_project_maven_repository was cached in the local repository, resolution will not be reattempted until the update interval of in-project has elapsed or updates are forced

但是我也把这个项目放到gitlab中并使用CI在mvn install -B命令下编译它 我的项目现在在gitlab CI服务器上找到依赖项并编译。

3 个答案:

答案 0 :(得分:0)

你需要通过maven将jar安装到你的本地仓库。除了将jar放入相应的文件夹之外,maven还做其他事情。

请参阅here

答案 1 :(得分:0)

要解决这个问题,我必须:

  1. 更改目录结构。我的组ID为&#34; metcarob.com.lib&#34;并将其作为单个目录。我不得不将其更改为3个目录。 metcarob / COM / lib中

  2. 我退出eclipse,删除目录〜/ .m2并重新启动eclipse。当我进行构建时,它构建得很好。

    Akber的评论是关键,但我无法将评论标记为正确以给予他信任。

  3. 感谢大家的帮助

答案 2 :(得分:0)

最有可能是两个问题之一:

  1. 组ID的每个部分都需要是自己的文件夹。
  2. 依赖项的pom.xml应存在于repo中的同一文件夹中。