Java 在 Eclipse 中打开 Maven POM 文件依赖层次时出错 - “项目读取错误”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6427212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 05:50:04  来源:igfitidea点击:

Error opening Maven POM file dependency hierarchy in Eclipse - "Project read error"

javaeclipsemavenpom.xml

提问by Michael

When I open a POM file and click on the "Dependency Hierarchy" tab at the bottom, it gives me the error, "Project read error". It works with other projects in the same workspace, just not with this one. Any ideas?

当我打开一个 POM 文件并单击底部的“依赖层次结构”选项卡时,它给了我错误“项目读取错误”。它适用于同一工作区中的其他项目,只是不适用于这个项目。有任何想法吗?

enter image description here

在此处输入图片说明

EDIT

编辑

In response to @Yhn's answer.

回应@Yhn 的回答。

  1. Running the compile and package phases outside of Eclipse from the command-line work as expected. It compiles the application and builds the final WAR file.
  2. Eclipse is indeed pointing to the default location of the Maven settings.xml file, so it should be aware of the custom repositories that are defined in it (my company has its own Maven repository).
  3. I can open and edit the POM file from Eclipse, so it must have read/write permissions to the file.
  4. The project is not configured in Eclipse as a Maven project, so I cannot run the package phase from Eclipse (I can only run it from the command-line).
  1. 从命令行运行 Eclipse 之外的编译和打包阶段按预期工作。它编译应用程序并构建最终的 WAR 文件。
  2. Eclipse 确实指向 Maven settings.xml 文件的默认位置,因此它应该知道其中定义的自定义存储库(我的公司有自己的 Maven 存储库)。
  3. 我可以从 Eclipse 打开和编辑 POM 文件,因此它必须对该文件具有读/写权限。
  4. 该项目未在 Eclipse 中配置为 Maven 项目,因此我无法从 Eclipse 运行包阶段(我只能从命令行运行它)。

I wonder if it has anything to do with the fact that I was having trouble building the project with Maven 3 because apparently some of the transitive dependencies are configured for Maven 1, which Maven 3 does not support(this is my theory anyway, based on some of the error messages). I can build the project with Maven 2, but I still get messages such as the following:

我想知道这是否与我在使用 Maven 3 构建项目时遇到问题有关,因为显然一些传递依赖项是为 Maven 1 配置的,而Maven 3 不支持(无论如何,这是我的理论,基于一些错误信息)。我可以使用 Maven 2 构建项目,但我仍然收到如下消息:

Downloading: http://dist.codehaus.org/mule/dependencies/maven2/org/codehaus/xfie/bcprov-jdk14/133/bcprov-jdk14-133.pom
[INFO] Unable to find resource 'org.codehaus.xfire:bcprov-jdk14:pom:133' in repsitory mule (http://dist.codehaus.org/mule/dependencies/maven2)

It must be able to find these dependences however, because it downloaded the JARs just fine and can build the application. It seems like the problem is that the dependencies don't have POM files associated with them, which is maybe why they cannot be used with Maven 3. This might also be why I cannot view the Dependency Hierarchy in Eclipse.

然而,它必须能够找到这些依赖项,因为它下载了 JAR 文件并且可以构建应用程序。似乎问题在于依赖项没有与之关联的 POM 文件,这可能是它们不能与 Maven 3 一起使用的原因。这也可能是我无法在 Eclipse 中查看依赖关系层次结构的原因。

EDIT 2

编辑 2

I converted the project to a Maven project by going to "Configure > Convert to Maven Project". When I open the POM file, I see the error:

我通过转到“配置 > 转换为 Maven 项目”将项目转换为 Maven 项目。当我打开 POM 文件时,我看到错误:

ArtifactDescriptorException: Failed to read artifact descriptor for woodstox:wst (Click for 140 more)

ArtifactDescriptorException: Failed to read artifact descriptor for woodstox:wst (Click for 140 more)

(woodstox:wst is another transitive dependency of the project). An error appears in the "Markers" view for seemingly every depedency and transitive dependency in my project. However, I can successfully build the project by doing a "Run As > Maven build". (Edit:This might be because this project has no Java source code, but the JARs of the dependencies correctly appear in the final WAR.) The Dependency Hierarchy still gives the same error--"Project read error".

(woodstox:wst 是项目的另一个传递依赖项)。对于我的项目中看似每个依赖项和传递依赖项,“标记”视图中都会出现一个错误。但是,我可以通过执行“运行方式 > Maven 构建”来成功构建项目。(编辑:这可能是因为该项目没有 Java 源代码,但依赖项的 JAR 正确出现在最终 WAR 中。)依赖关系层次结构仍然给出相同的错误——“项目读取错误”。

About the "Unable to find resource" messages--but this only appears for a handful of transitive dependencies. The project has many more transitive dependencies, but these messages do not appear for them. It seems like, because the dependencies do not have POM files, that Maven tries to search for them every time the project is built. Is this normal not to have POMs??

关于“无法找到资源”消息——但这仅出现在少数可传递依赖项中。该项目具有更多的传递依赖项,但不会为他们显示这些消息。看起来,因为依赖项没有 POM 文件,所以每次构建项目时 Maven 都会尝试搜索它们。没有 POM 是正常的吗??

How might I go about getting a repo manager? Is this something that would have to be installed on the company's Maven repository or can you install it on your own workstation?

我怎样才能找到一个回购经理?这是必须安装在公司的 Maven 存储库上的东西还是您可以将其安装在自己的工作站上?

采纳答案by Glenn

I had this problem with some non-maven jars that I needed to include in my maven project. I put the jars in my local repository using this maven command:

我在一些非 Maven jar 中遇到了这个问题,我需要将其包含在我的 Maven 项目中。我使用这个 maven 命令将 jars 放在我的本地存储库中:

mvn install:install-file -Dfile=/test/gov.nist.xccdf-1.2.jar -DgroupId=gov.nist -DartifactId=xccdf -Dpackaging=jar -Dversion=1.2

Then I referred to them as dependencies in my pom.xml:

然后我在我的 pom.xml 中将它们称为依赖项:

    <dependency>
        <groupId>gov.nist</groupId>
        <artifactId>xccdf</artifactId>
        <version>1.2</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>

This worked fine for a while, but I must have upgraded something in eclipse, and I started getting the error you describe.

这在一段时间内运行良好,但我必须在 eclipse 中升级了某些东西,并且我开始收到您描述的错误。

The fix is to take them out of the local repository, and redo the install-file asking maven to generate a pom for you:

解决方法是将它们从本地存储库中取出,并重做安装文件,要求 maven 为您生成一个 pom:

mvn -DgeneratePom=true install:install-file -Dfile=/test/gov.nist.xccdf-1.2.jar -DgroupId=gov.nist -DartifactId=xccdf -Dpackaging=jar -Dversion=1.2

The command will cause a pom to be generated in the same directory (within your local repo) where the jar is placed.

该命令将导致在放置 jar 的同一目录(在您的本地存储库中)中生成一个 pom。

In recent versions of eclipse maven support, the maven build is still done with maven 2 (if you right-click your pom.xml, choose run as mvn package for example). The dependency analysis is now done with an embedded maven 3 plugin, which doesn't like a dependency that has no pom.xml.

在最新版本的 eclipse maven 支持中,maven 构建仍然使用 maven 2 完成(例如,如果您右键单击 pom.xml,选择作为 mvn 包运行)。依赖分析现在使用嵌入式 maven 3 插件完成,它不喜欢没有 pom.xml 的依赖。

回答by Yhn

Given the information through the comments:

通过评论给出的信息:

mvn compile/mvn package work through console (I'm assuming outside of eclipse). Based on that, the POM file should be correct and dependencies can be resolved.

mvn compile/mvn 包通过控制台工作(我假设在 eclipse 之外)。基于此,POM 文件应该是正确的,并且可以解决依赖关系。

However; it could be that eclipse's settings aren't correct. For example, if eclipse has some own maven properties (instead of the default ~/.m2/settings.xml file); I can imagine it to fail resolving dependencies configured in the settings.xml used by maven itself. The settings for this should be in the Eclipse Preferences @ Maven > User Settings.

然而; 可能是 eclipse 的设置不正确。例如,如果 eclipse 有一些自己的 maven 属性(而不是默认的 ~/.m2/settings.xml 文件);我可以想象它无法解析 maven 本身使用的 settings.xml 中配置的依赖项。此设置应在 Eclipse Preferences @ Maven > User Settings 中。

Also make sure that Eclipse can actually read the file (not locked, correct rights, etc).

还要确保 Eclipse 可以实际读取文件(未锁定、正确的权限等)。

Should this seem to be correct; can you try to run the mvn goal compile from eclipse? You can do this by right-clicking the project and selecting run as > maven package. That way it should run maven with the same settings as eclipse is using, and might show any additional errors in it's configuration.

这应该是正确的吗?您可以尝试从 Eclipse 运行 mvn 目标编译吗?您可以通过右键单击项目并选择 来执行此操作run as > maven package。这样,它应该使用与 eclipse 使用的设置相同的设置运行 maven,并且可能会在其配置中显示任何其他错误。

-- In response to additional information:

——回应补充信息:

Basically it tells you - when using Maven 2 - that it can't find a dependency resource (in this case bcprov-jdk14) in the given repository (codehaus/mule). When I search that maven module (bcprov-jdk14) I find it in the Maven central repo (through our local nexus) @ repo1.maven.org/maven2. Maybe that causes the error you're getting with Maven2?

基本上它告诉你 - 当使用 Maven 2 时 - 它在给定的存储库(codehaus/mule)中找不到依赖资源(在这种情况下是 bcprov-jdk14)。当我搜索该 Maven 模块 (bcprov-jdk14) 时,我在 Maven 中央仓库中找到了它(通过我们的本地连接)@ repo1.maven.org/maven2。也许这会导致您在使用 Maven2 时遇到错误?

And as the Maven 3 doc says; for Maven 1.x repo's; you should proxy them through a repo manager that can serve it to you as a maven 2 repository (I believe we do that here too for some repo's through Sonatype Nexus OSS)

正如 Maven 3 文档所说;对于 Maven 1.x 存储库;你应该通过一个 repo manager 代理它们,它可以作为 maven 2 存储库提供给你(我相信我们在这里也通过 Sonatype Nexus OSS 为一些 repo 这样做)

ps.: Enabling maven dependency management in eclipse should be enough to be able to use maven run targets; if you would want to test it.

ps.:在eclipse中启用maven依赖管理应该就可以使用maven run目标了;如果你想测试它。

--

——

Sound like it can be multiple problems... given that the normal maven build works fine, one would think that maven can at least get the artifacts it depends upon and their dependencies... Yet, eclipse doesn't seem to be able to.

听起来它可能有多个问题......鉴于正常的 maven 构建工作正常,人们会认为 maven 至少可以获取它所依赖的工件及其依赖项......然而,eclipse 似乎无法.

Double check if your Eclipse internet connection settings are correct? Since you were talking about a company repo, I'm assuming there will probably also be a proxy (I had to set up my Eclipse to use that one too; though for plugins (see next point)).

仔细检查您的 Eclipse 互联网连接设置是否正确?由于您在谈论公司回购,因此我假设可能还会有一个代理(我必须设置我的 Eclipse 以使用该代理;但对于插件(见下一点))。

Another possibility, from experience, can be a rule-based proxy block on *.pom url requests (our proxy here blocks that to force usage of the local repo manager, how evil and annoying that is :(). You might want to try and open the .pom file it tries to download manually in your browser to see if this is the case (I can't, for example...).

另一种可能性,根据经验,可以是 *.pom url 请求上的基于规则的代理块(我们的代理在这里阻止强制使用本地 repo 管理器,这是多么邪恶和烦人:()。您可能想尝试并打开它尝试在浏览器中手动下载的 .pom 文件,看看是否是这种情况(例如,我不能......)。

To get the repo set up, you would probably have to ask the one responsible for the repository to add it as a maven2 proxy.

要设置存储库,您可能必须要求负责存储库的人将其添加为 maven2 代理。

At the very least, it seems Eclipse is having issues getting the dependency poms (which are needed to build the dependency tree) from the internet. You could always try to ask some ICT crew (if they are capable enough...) about it at your company, maybe they have some useful hints.

至少,Eclipse 似乎在从 Internet 获取依赖项 poms(构建依赖关系树所需)时遇到问题。你可以试着问问你公司的一些 ICT 工作人员(如果他们有足够的能力......),也许他们有一些有用的提示。

回答by OblongZebra

I had the same problem. If you made your project a maven project, you should run:

我有同样的问题。如果您将项目设为 Maven 项目,则应运行:

  • Right Mouse Click on project | Maven | Update Dependencies or
  • Right Mouse Click on project | Maven | Update Project Configuration
  • 鼠标右键单击项目 | 马文 | 更新依赖项或
  • 鼠标右键单击项目 | 马文 | 更新项目配置

That worked for me.

那对我有用。

回答by jason zhang

I had the same problem when I added a new dependency to pom.xml without network connection. After this, I had so many problems such as "Missing artifacts", "Missing Descriptor", or "Project Read error". I solved this

当我在没有网络连接的情况下向 pom.xml 添加新依赖项时,我遇到了同样的问题。在此之后,我遇到了很多问题,例如“缺少工件”、“缺少描述符”或“项目读取错误”。我解决了这个

  1. delete the bad dependency just added from local repository.
  2. rebuild local index.
  3. re-add the dependency
  1. 删除刚刚从本地存储库添加的错误依赖项。
  2. 重建本地索引。
  3. 重新添加依赖

回答by traysine zheng

<properties>
    <!-- ********************** -->

    <!-- Plugin's properties -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.7</java.version>
</properties>

this pom setting worked for me

这个 pom 设置对我有用

回答by Mike

Usually this happens if there is a typo in the pom that Maven cannot understand and then it throws Project read error. Like in my case I copied a maven dependency snippet and I by passed the version. Instead of typing the actual version # it was getting it dynamically ${asciidoctorj.version}and my pom didn't have this in the properties section. So I got this error. Once I removed that and put a version number it started working.

通常,如果 pom 中有一个 Maven 无法理解的错字,然后它抛出Project read error. 就像在我的情况下,我复制了一个 Maven 依赖项片段,并通过了版本。不是输入实际版本#而是动态获取它,${asciidoctorj.version}而我的 pom 在属性部分没有这个。所以我得到了这个错误。一旦我删除它并输入版本号,它就开始工作了。

回答by reid

I had this after copying a local repository folder from another machine. The fix was to go into the repository folder I copied and delete _remote.repositories along with the 'LastUpdated' files then refresh the Maven dependencies in Eclipse (Alt+F5)

从另一台机器复制本地存储库文件夹后,我有了这个。修复方法是进入我复制的存储库文件夹并删除 _remote.repositories 以及“LastUpdated”文件,然后刷新 Eclipse 中的 Maven 依赖项(Alt+F5)

回答by Jianwu Chen

I faced same situation today. In my case it's caused by dependency name in wrong case. E.g.

我今天面临同样的情况。在我的情况下,它是由错误的依赖名称引起的。例如

Project A -> Project B -> Project C In project B's pm file, I mistakenly specified the dependency artifacts name with "c" in stead of "C".

项目 A -> 项目 B -> 项目 C 在项目 B 的 pm 文件中,我错误地用“c”而不是“C”指定了依赖工件名称。

As in mac os, the files system is case insensitive. so I can build it in command line without detecting this mistake.

在 mac os 中,文件系统不区分大小写。所以我可以在命令行中构建它而不会检测到这个错误。

In Eclipse it breaks, but it provides very bad error message. In the error list, it says "dependency problem", but the name of dependency is empty. It also can't identify which line in the POM causes the problem.

在 Eclipse 中它会中断,但它提供了非常糟糕的错误消息。在错误列表中显示“依赖问题”,但依赖名称为空。它也无法识别 POM 中的哪一行导致了问题。

When try to open "Effective POM" in POM viewer, it will show project read error. In the pop up error dialog box, it will show:

当尝试在 POM 查看器中打开“Effective POM”时,它会显示项目读取错误。在弹出的错误对话框中,会显示:

Could not read maven project
java.nio.channels.OverlappingFileLockException 

All the messages are useless and misleading.

所有的信息都是无用的和误导性的。

I finally detected this problem by submit to Jenkins CI after wasted hours of time.

在浪费了几个小时的时间之后,我终于通过提交给 Jenkins CI 发现了这个问题。