mavenjardependenciespom.xmlmvn-repo

Some Remote Maven Repository Dependencies Not Found


I am trying to convert a large java web app to a maven project in Eclipse. Most of the jar files we use are on the central Maven repo, but 6 are not. I researched about how to create a shared remote (personal) Maven repo. I created one on a shared server with other developers on my team (example shared network location SHAREDSERVER). I set up my pom.xml to recognize that repo and central Maven repo:

  <repositories>
    <repository>
        <id>custom-repo</id>
        <url>file://SHAREDSERVER/custom/repo</url>
    </repository>
    <repository>
        <id>central</id>
        <url>https://repo.maven.apache.org/maven2</url>
    </repository>
  </repositories>

Then, on the server, I run the Maven command:

mvn install:install-file
    -Dfile=C:\location\of\jar\file
    -DgroupId="com.my.group"
    -DartifactId=art-one-name
    -Dversion="1.0"
    -Dpackaging=jar
    -DlocalRepositoryPath=C:\custom\repo

No errors are displayed, so I check that all files are at the location C:\custom\repo\com\my\group -- they are all there.

Then on my local machine, where I'm developing the project, I add this dependency to the pom.xml:

<dependency>
    <groupId>com.my.group</groupId>
    <artifactId>art-one-name</artifactId>
    <version>1.0</version>
</dependency>

No errors are shown in my Eclipse IDE or elsewhere. (And all dependencies from the central Maven repo are obtained successfully.)

Then I repeat the process to add artifact art-two-name to the same group com.my.group. There are no errors in the process. However, when I include the dependency for art-two-name in my project's pom.xml, it says:

Missing artifact com.my.group:art-two-name:jar:1.0
Could not find artifact com.my.group:art-two-name:jar:1.0 in custom-repo (file://SHAREDSERVER/custom/repo)

I tried deleting the repo and made a new one; but the same issues came up. I tried running the project from Eclipse to see if the error message shown in the pom.xml were meaningless/superficial, but it doesn't deploy, giving me the error:

Error reading file C:\Users\myUsername\.m2\repository\com\my\group\art-two-name\1.0\art-two-name-1.0.jar
C:\Users\myUsername\.m2\repository\com\my\group\art-two-name\1.0\art-two-name-1.0.jar (The system cannot find the file specified)

So clearly, it's not getting the jar file from custom-repo.

Any ideas why it can find only one of the dependencies/jars, when I can see them all in custom-repo?

(Note: this is just an example; I had actually added all the jar files to custom-repo first, then I tried adding them as dependencies in pom.xml and realized that Eclipse could only find one of the dependencies.)


Solution

  • I don't know why all the errors I had were so unhelpful and all the documentation I found didn't say this, but the issue was this:

    My custom repository block in pom.xml needed this change:

    <url>file://SHAREDSERVER/custom/repo</url>
    

    should have been

    <url>file:\\SHAREDSERVER\custom\repo</url>
    

    Note the direction of \ vs. /! This is the direction of the slashes as used in Windows file explorer! (This is for a repository that is on a shared network location.)