Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Maven找不到本地依赖项_Java_Maven_Repository_Maven 3_Pom.xml - Fatal编程技术网

Java Maven找不到本地依赖项

Java Maven找不到本地依赖项,java,maven,repository,maven-3,pom.xml,Java,Maven,Repository,Maven 3,Pom.xml,TL;DR Maven在存储库中找不到::jar:1.0file:///.m2/repository/。包实际上位于/.m2/repository///1.0/ 我不想理解Maven,但我可以想象的两个潜在原因是: 它与:和/相混淆(即UNIX风格的路径分隔符与:在Maven中的含义不同),或者 如果:和/实际上被解释为相同,则它搜索的路径包括另一个子目录级别jar,而该子目录级别在实际目录结构中不存在 详细说明 我试图在Maven中本地导入一个包(因为该包没有在线部署)。stackover

TL;DR

Maven在存储库中找不到
::jar:1.0
file:///.m2/repository/。包实际上位于
/.m2/repository///1.0/

我不想理解Maven,但我可以想象的两个潜在原因是:

  • 它与
    /
    相混淆(即UNIX风格的路径分隔符与
    在Maven中的含义不同),或者
  • 如果
    /
    实际上被解释为相同,则它搜索的路径包括另一个子目录级别
    jar
    ,而该子目录级别在实际目录结构中不存在
详细说明

我试图在Maven中本地导入一个包(因为该包没有在线部署)。stackoverflow上的各种答案(如和)建议在包含软件包的jar上运行
mvn install
(假设jar位于
/usr/share/java
,是1.0版,等等):

mvn install
命令将包部署到
/.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> $
$mvn install:install file-Dfile=/usr/share/java/-1.0-SNAPSHOT.jar-DgroupId=-DartifactId=-Dversion=1.0-dpackage=jar-DgeneratePom=true
[信息]正在扫描项目。。。
[信息]
[信息]------------------------------------------------------------------------
[信息]楼宇1.0-SNAPSHOT
[信息]------------------------------------------------------------------------
[信息]
[信息]---maven安装插件:2.4:安装文件(默认cli)@---
[INFO]正在将/usr/share/java/economicsl-1.0-SNAPSHOT.jar安装到/.m2/repository//1.0//-1.0.jar
[INFO]安装/tmp/mvninstall25601239899457078.pom到/.m2/repository///1.0//-1.0.pom
[信息]------------------------------------------------------------------------
[信息]建立成功
[信息]------------------------------------------------------------------------
[信息]总时间:0.489秒
[信息]完成时间:2017-05-11T19:11:12+01:00
[信息]最终内存:9M/292M
[信息]------------------------------------------------------------------------
$
该软件包也出现在
/.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> $
$ls`/.m2/存储库///1.0/`
-1.0.JAR-1.0.JAR.lastUpdated-1.0.pom\u remote.repositories
$
但是,构建尝试导入包的项目失败:

<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> $
$mvn软件包-U
[信息]正在扫描项目。。。
[信息]
[信息]------------------------------------------------------------------------
[信息]楼宇1.0-SNAPSHOT
[信息]------------------------------------------------------------------------
下载:file:///.m2/repository///1.0/-1.0.jar
下载:https://repo.maven.apache.org/maven2///1.0/-1.0.jar
[信息]------------------------------------------------------------------------
[信息]生成失败
[信息]------------------------------------------------------------------------
[信息]总时间:0.730秒
[信息]完成时间:2017-05-12T17:59:43+01:00
[信息]最终内存:13M/292M
[信息]------------------------------------------------------------------------
[错误]无法在项目上执行目标:无法解析project::jar:1.0的依赖关系-快照:无法在存储库中找到工件::jar:1.0(file:///.m2/repository/)->[帮助1]
[错误]
[错误]要查看错误的完整堆栈跟踪,请使用-e开关重新运行Maven。
[错误]使用-X开关重新运行Maven以启用完整调试日志记录。
[错误]
[错误]有关错误和可能的解决方案的更多信息,请阅读以下文章:
[错误][帮助1]http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
$
如果在
pom.xml
中定义了
/usr/share/java
中jar的绝对路径,则项目将成功构建,并警告不使用绝对路径,但执行失败,因为这次没有再次找到包

Maven版本是ApacheMaven3.3.9

占位符

  • 应该导入另一个包的项目。所有终端命令都是从该项目的根目录执行的(它的
    pom.xml
    所在的位置)
  • 应该导入其他包的项目的ArtifactID
  • GroupID,该项目应导入另一个包
  • 要导入的项目的ArtifactID
  • 要导入的项目的组ID
  • 用户的主目录,即
    /home/
  • 终端提示

您的文件扩展名“JAR”是大写的,而maven的文件扩展名“JAR”是小写的。如果您的文件系统区分大小写,那么这一点很重要。

刚刚注意到,您的文件扩展名“JAR”是大写的,而maven看起来是小写的“JAR”。如果您的文件系统区分大小写,那么这很重要。@gogstad是的,您完全正确。(因此,必须使用
-dpackage=jar
调用
mvn install
,而不是使用
-dpackage=jar
来修复此问题。)如果您可以将此作为答案重新发布,我将接受。
<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> $