简体   繁体   中英

Maven failing to find jar from Project Repository

I have a jar file which I need to include in my project. I am using eclipse with Maven

I created the following folder in my project on my computer:

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

and I placed a file there called:

nachocalendar-0.23.jar

I then added the dependancy to my POM file:

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

I also added the Repo into my pom file:

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

from what I understand this should work. When I right click on my project select run as and maven install I get the following error:

[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/

I have followed all the steps I can see for creating an in project repository but it still seems to not be able to find the file.

Does anyone know of a step I am missing?

Thanks Robert

Update: I must have made mutiple mistakes. Akber found my first mistake: I have changed the folder so the group ID is in seperate folders: (metcarob.com.lib is now metcarob.com.lib) The jar file is now in: /home/robert/eclipse/BobProjects/BobDiary/in_project_maven_repository/metcarob/com/lib/nachocalendar/0.23

I have verified this because the following directory exists in my machine: ~/.m2/repository/metcarob/com/lib/nachocalendar/0.23

I have moved the file, restarted eclipse and re-ran maven clean and maven install.

The error is now:

[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

However I also put this project into gitlab and use CI to compile it there with the command mvn install -B My project now finds the dependency and compiles on the gitlab CI server.

you need to install the jar via maven into your local repo. maven does other things too except for just placing the jar into the respective folder.

please see here

To fix this I had to:

  1. Change the directory structure. I had the group ID of "metcarob.com.lib" and had that as a single directory. I had to change that to 3 directories. metcarob/com/lib

  2. I quit eclipse, deleted the directory ~/.m2 and restarted eclipse. When I did a build it built fine.

    Akber's comment was the key but I can't mark a comment as correct to give him credit.

Thanks everyone for the help

Most likely, one of two problems:

  1. Each part of the group id needs to be its own folder.
  2. The pom.xml of the dependency should exist int the same folder in the repo.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM