项目“X”缺少必需的 Java 项目:“Y”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22050194/
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-13 13:15:54  来源:igfitidea点击:

Project 'X' is missing required Java project: 'Y'

javaeclipsemavendependency-management

提问by Farah

I've created a Maven project, of packaging type "jar", called "Y" I've done "Maven install", and I could find it in my local repository..

我创建了一个 Maven 项目,包装类型为“jar”,名为“Y”,我已经完成了“Maven 安装”,我可以在我的本地存储库中找到它。

Then, I've created another project, of packaging type "war", called "X". In this project, I added a dependency to "Y" jar, as follows :

然后,我创建了另一个项目,包装类型为“war”,称为“X”。在这个项目中,我添加了一个对“Y”jar的依赖,如下:

<dependency>
   <groupId>my.pck</groupId>
   <artifactId>Y</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <type>jar</type>
</dependency>

My problem is that when I close the project "Y", I receive this error :

我的问题是,当我关闭项目“Y”时,我收到此错误:

Project 'X' is missing required Java project: 'Y'

But, it doesn't say "missing artifact"... and in all the cases, when I try to deploy "X" I get this : java.lang.ClassNotFoundException:for every class that I have in project "Y" and used in the project "X"...

但是,它并没有说“缺少工件”......在所有情况下,当我尝试部署“X”时,我得到这个:java.lang.ClassNotFoundException:对于我在项目“Y”中拥有并在项目“X”中使用的每个类“……

采纳答案by Farah

Thank you @Eldad, your comment helped me to detect the problem.

谢谢@Eldad,您的评论帮助我发现了问题。

Under Eclipse IDE : Right click on "X" project > Build Path > Configure Build Path > Project > Check Y > Click on "Remove"

在Eclipse IDE下:右键单击“X”项目>构建路径>配置构建路径>项目>选中Y>点击“删除”

Now no error while deploying the X war.

现在在部署 X 战争时没有错误。

回答by keshlam

This error message means that one of your eclipse projects has a dependency on another one. which you haven't set up or which isn't open. Either modify the Eclipse build path so it no longer requires that other project (replace that dependency with a reference to a jarfile or other source of the code/resources being used), or get that project set up.

此错误消息意味着您的一个 Eclipse 项目依赖于另一个。您尚未设置或未打开的。要么修改 Eclipse 构建路径,使其不再需要该其他项目(将该依赖项替换为对 jarfile 或正在使用的代码/资源的其他源的引用),要么设置该项目。

回答by raffian

I've seen this error in the past; You mentioned eclipse, so it may be related to moving an Eclipse project from one workspace to another.

我过去见过这个错误;您提到了 eclipse,因此它可能与将 Eclipse 项目从一个工作区移动到另一个工作区有关。

Check .classpathand .projectfiles for links to invalid directory resources; adjust as needed:

检查.classpath并记录.project无效目录资源的链接;根据需要调整:

<linkedResources>
    <link>
        <name>.link_to_something</name>
        <type>2</type>
        <location>C:/Users/user/projects/someproject/plugins</location>
    </link>
</linkedResources>

回答by Neeraj Bhatnagar

OK, if the above does not work, try the following. It worked for me.

好的,如果上述方法不起作用,请尝试以下方法。它对我有用。

Moral of the story: Periodically save .metadata and .recommenders of your project. They may be useful.

故事寓意:定期保存项目的 .metadata 和 .recommenders。它们可能有用。

Why the problem happened: I added project Y to Project X and then removed it. Eclipse did not properly and fully remove Y and began to complain as above.

问题发生的原因:我将项目 Y 添加到项目 X,然后将其删除。Eclipse 没有正确和完全删除 Y 并开始如上所述抱怨。

Versions and configuration: Eclipse Neon. Legacy. No maven etc.

版本和配置:Eclipse Neon。遗产。没有maven等。

What worked: 0) Exit eclipse.

什么工作:0)退出日食。

1) Made a copy of the entire directory of X. To be on the safe side.

1) 复制 X 的整个目录。为了安全起见。

2) deleted the above two . directories.

2) 删除了上面两个。目录。

3) Copied old saved versions of these directories to replace the deleted versions.

3) 复制这些目录的旧保存版本以替换已删除的版本。

4) Restarted Eclipse. It made some routine complains. But I did the following:

4)重新启动Eclipse。它引起了一些例行的抱怨。但我做了以下事情:

4.1) Clean 4.2) Refresh 4.3) Build all

4.1) 清理 4.2) 刷新 4.3) 全部构建

5) It worked. I exited and restarted Eclipse many times to make sure that the problem does not reappear. So far so good.

5)它起作用了。我多次退出并重新启动 Eclipse 以确保问题不会再次出现。到现在为止还挺好。