3

TL;DR

Maven does not find <importedGroupid>:<importedArtifactid>:jar:1.0 in repository file://<homeDirectory>/.m2/repository/. The package actually is in <homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/

I do not presume to understand Maven, but the two potential reasons I could imagine are:

  • it gets confused with : and / (i.e. UNIX style path seperator vs. whatever : means in Maven), or
  • if : and / are actually interpreted as the same, the path it searches for includes another subdirectory level jar that is not present in the real directory structure.

Detailed Explanation

I was trying to import a package locally in Maven (as the package is not deployed online). Various answers (e.g., this, and this) on stackoverflow recommend running mvn install on the jar containing the package like so (assuming the jar is in /usr/share/java, is version 1.0, etc. etc.):

mvn install:install-file -Dfile=/usr/share/java/<importedArtifactid>-1.0-SNAPSHOT.jar -DgroupId=<importedGroupid> -DartifactId=<importedArtifactid> -Dversion=1.0 -Dpackaging=JAR -DgeneratePom=true

and defining this in the current package's pom.xml by adding:

<repository>
  <id>repository</id>
  <url>file://${user.home}/.m2/repository/</url>
</repository>

The mvn install command deploys the package into <homeDirectory>/.m2/repository/. So far, this works fine:

<prompt> $ mvn install:install-file -Dfile=/usr/share/java/<importedArtifactid>-1.0-SNAPSHOT.jar -DgroupId=<importedGroupid> -DartifactId=<importedArtifactid> -Dversion=1.0 -Dpackaging=JAR -DgeneratePom=true
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building <currentDirectoryProject> 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ <currentDirectoryProjectArtifactid> ---
[INFO] Installing /usr/share/java/economicsl-1.0-SNAPSHOT.jar to <homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/<importedArtifactid>-1.0.JAR
[INFO] Installing /tmp/mvninstall256012398997457078.pom to <homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/<importedArtifactid>-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.489 s
[INFO] Finished at: 2017-05-11T19:11:12+01:00
[INFO] Final Memory: 9M/292M
[INFO] ------------------------------------------------------------------------
<prompt> $

The package also appears in <homeDirectory>/.m2/repository/

<prompt> $ ls `<homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/`
<importedArtifactid>-1.0.JAR              <importedArtifactid>-1.0.jar.lastUpdated  <importedArtifactid>-1.0.pom              _remote.repositories
<prompt> $

However, building the project that attempts to import the package fails:

<prompt> $ mvn package -U
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building <currentDirectoryProject> 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: file://<homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/<importedArtifactid>-1.0.jar
Downloading: https://repo.maven.apache.org/maven2/<importedGroupid>/<importedArtifactid>/1.0/<importedArtifactid>-1.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.730 s
[INFO] Finished at: 2017-05-12T17:59:43+01:00
[INFO] Final Memory: 13M/292M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project <currentDirectoryProjectArtifactid>: Could not resolve dependencies for project <currentDirectoryProjectGroupid>:<currentDirectoryProjectArtifactid>:jar:1.0-SNAPSHOT: Could not find artifact <importedGroupid>:<importedArtifactid>:jar:1.0 in repository (file://<homeDirectory>/.m2/repository/) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
<prompt> $

If an absolute path to the jar in /usr/share/java is defined in the pom.xml, the project builds successfully with a warning about not using absolute paths, but execution fails as it does not find the package again this time.

Maven version is Apache Maven 3.3.9.

Placeholders

  • <currentDirectoryProject> The project that is supposed to import the other package. All terminal commands are executed from the root directory of this project (this is where its pom.xml resides).
  • <currentDirectoryProjectArtifactid> ArtifactID of the project that is supposed to import the other package.
  • <currentDirectoryProjectGroupid> GroupID of the project that is supposed to import the other package.
  • <importedArtifactid> ArtifactID of the project that is to be imported
  • <importedGroupid> GroupID of the project that is to be imported
  • <homeDirectory> the user's home directory, i.e. /home/<userName>
  • <prompt> terminal prompt
Community
  • 1
  • 1
0range
  • 2,088
  • 1
  • 24
  • 32
  • 1
    Just noticed that you have a file extension "JAR" in upper case and maven is looking "jar" in lower case. If your file system is case sensitive, then that's important. – gogstad May 12 '17 at 17:58
  • @gogstad Yes, you are absolutely right. (Consequently, `mvn install` must be called with `-Dpackaging=jar`, not with `-Dpackaging=JAR` to fix this.) If you could re-post this as answer, I will accept it. – 0range May 12 '17 at 18:10

1 Answers1

5

You have a file extension "JAR" in upper case and maven is looking "jar" in lower case. If your file system is case sensitive, then that's important.

gogstad
  • 3,607
  • 1
  • 29
  • 32
  • God bless you for this answer, I have been driving myself insane trying to figure out why this build setup I inherited worked fine on our OSX machines and failed in the Linux CI environment I've been trying to set up – Jake Sep 15 '21 at 12:15