Eclipse 无法加载资源目录(构建路径问题)

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

Eclipse cannot load resources directory (Build Path Problem)

javaeclipsemaven-2maven

提问by user496949

I found there is an exclamation mark in the icon of my project. I guess it is caused by the resources directory is not loaded.

我发现我的项目图标中有一个感叹号。估计是资源目录没有加载造成的。

Here is part of my .classpath file, anything can be wrong?

这是我的 .classpath 文件的一部分,有什么问题吗?

<classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
  <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>

The problem Eclipse shows is

Eclipse 显示的问题是

Project 'dingdong' is missing required source folder: 'src/main/resources' dingdong Build path Build Path Problem

Project 'dingdong' is missing required source folder: 'src/main/resources' dingdong Build path Build Path Problem

回答by esaj

Just adding this here if someone stumbles on the same question: The problem was solved by refreshing the project (Selecting the project root and hitting F5), see comments.

如果有人偶然发现同一个问题,只需在此处添加:通过刷新项目(选择项目根目录并按 F5)解决了问题,请参阅评论。

Eclipse does not refresh the workspace projects by default when starting up. You can add an start-up option (the flag is -refresh, see herefor details) for performing a global refresh of the workspace on startup. This will reconcile any changes that were made in the file system since the platform was last run.

默认情况下,Eclipse 在启动时不会刷新工作区项目。您可以添加启动选项(标志是-refresh,请参阅此处了解详细信息)以在启动时执行工作区的全局刷新。这将协调自平台上次运行以来在文件系统中所做的任何更改。

Removing and re-adding the source folder to project Build path can be done like this:

将源文件夹删除并重新添加到项目构建路径可以这样完成:

  • Right click on the source folder, select Build path -> Remove from build path
  • Select the folder from the "normal" (non-source folder) -directory tree (usually shows way down in your project tree), right click the desired directory and select Build path -> Use as Source folder
  • 右键单击源文件夹,选择构建路径 -> 从构建路径中删除
  • 从“普通”(非源文件夹)-目录树(通常在项目树中向下显示)中选择文件夹,右键单击所需目录并选择构建路径 -> 用作源文件夹

回答by scottysseus

Refreshing the project, which is what the accepted answer suggests, failed for me.

刷新项目,这是公认的答案所暗示的,对我来说失败了。

Here is what I did to resolve this issue:

这是我为解决此问题所做的工作:

  1. Right click , and then select Build Path -> Configure Build Path... -> Order and Export
  2. Look for the src/main/resources folder in the entries list. Mine was called <my project folder>/src/main/resources.
  3. Move <my project folder>/src/main/resourcesto the bottom of the dependency list by selecting it and clicking the button titled Bottom.
  1. 右键单击 ,然后选择 Build Path -> Configure Build Path... -> Order and Export
  2. 在条目列表中查找 src/main/resources 文件夹。我的被​​称为<my project folder>/src/main/resources
  3. <my project folder>/src/main/resources通过选择依赖项列表并单击标题为 的按钮移动到依赖项列表的底部Bottom

This resolved the issue for me. In my case, the resourcesentry was above the src/main/javaand src/main/testentries, which seems to have been causing problems.

这为我解决了这个问题。就我而言,resources条目位于src/main/javasrc/main/test条目之上,这似乎引起了问题。