Maven找不到本地依赖

时间:2017-05-12 17:45:16

标签: java maven repository maven-3 pom.xml

TL; DR

Maven在存储库MultiValueMap<String, String> testMap = new MultiValueMap<String, String>(); if (atlastMap.hasNext()) { System.out.println("Found a way"); } 中找不到<importedGroupid>:<importedArtifactid>:jar:1.0。该包实际上在file://<homeDirectory>/.m2/repository/

我不认为理解Maven,但我能想象的两个潜在原因是:

  • 它与<homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/:混淆(即UNIX样式路径分隔符与Maven中/的含义相比)或
  • 如果::实际上被解释为相同,则其搜索的路径包含实际目录结构中不存在的另一个子目录级/

详细说明

我试图在Maven中本地导入一个包(因为该包未在线部署)。 stackoverflow上的各种答案(例如,thisthis)建议在包含包的jar上运行jar,如果是这样(假设jar在mvn install中,则是版本1.0等等。):

/usr/share/java

并通过添加:

在当前包mvn install:install-file -Dfile=/usr/share/java/<importedArtifactid>-1.0-SNAPSHOT.jar -DgroupId=<importedGroupid> -DartifactId=<importedArtifactid> -Dversion=1.0 -Dpackaging=JAR -DgeneratePom=true 中定义此内容
pom.xml

<repository> <id>repository</id> <url>file://${user.home}/.m2/repository/</url> </repository> 命令将程序包部署到mvn install。到目前为止,这很好用:

<homeDirectory>/.m2/repository/

该套餐还会显示在<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> $

<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> $

如果在<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> $ 中定义了/usr/share/java中jar的绝对路径,则项目会成功构建,并显示不使用绝对路径的警告,但执行失败,因为它再次找不到包这一次。

Maven版本是Apache Maven 3.3.9。

占位符

  • pom.xml应该导入其他包的项目。所有终端命令都从该项目的根目录执行(这是<currentDirectoryProject>所在的位置。)
  • pom.xml应该导入其他包的项目的ArtifactID。
  • <currentDirectoryProjectArtifactid>应该导入其他包的项目的GroupID。
  • <currentDirectoryProjectGroupid>要导入的项目的ArtifactID
  • <importedArtifactid>要导入的项目的GroupID
  • <importedGroupid>用户的主目录,即<homeDirectory>
  • /home/<userName>终端提示

1 个答案:

答案 0 :(得分:4)

你有一个大写的文件扩展名“JAR”,maven看起来是小写的“jar”。如果您的文件系统区分大小写,那么这很重要。