Eclipse+Maven src/main/java 在包资源管理器的 src 文件夹中不可见
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18790106/
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
Eclipse+Maven src/main/java not visible in src folder in Package Explorer
提问by Sebastian Dusza
I'm wondering why I can't see following folders in src node in Package Explorer
我想知道为什么我在包资源管理器的 src 节点中看不到以下文件夹
src/main/java
src/main/resources
src/test/java
src/test/resources
I can access those folders as direct children of the project and they exist in the file system.
我可以作为项目的直接子级访问这些文件夹,它们存在于文件系统中。
I'm using Spring Tool Suite (STS of Eclipse).
我正在使用 Spring Tool Suite(Eclipse 的 STS)。
Maybe I can configure Eclipse somehow ?
也许我可以以某种方式配置 Eclipse?
回答by Ranjith Sekar
I have solved this issue by below steps:
我已经通过以下步骤解决了这个问题:
- Right click the Maven Project -> Build Path -> Configure Build Path
- In Order and Export tab, you can see the message like '2 build path entries are missing'
- Now select 'JRE System Library' and 'Maven Dependencies' checkbox
- Click OK
- 右键单击Maven项目->构建路径->配置构建路径
- 在“订购和导出”选项卡中,您可以看到“缺少 2 个构建路径条目”之类的消息
- 现在选择“JRE 系统库”和“Maven 依赖项”复选框
- 单击确定
Now you can see below in all type of Explorers (Package or Project or Navigator)
现在您可以在所有类型的资源管理器(包或项目或导航器)中看到以下内容
src/main/java
src/main/resources
src/test/java
回答by miko?ak
Eclipse filters out folders that are marked as source from the "raw" folder path. That is, they are visible only as source folders:
Eclipse 会从“原始”文件夹路径中过滤掉标记为源的文件夹。也就是说,它们仅作为源文件夹可见:
If you can't see them in either place, then they
如果你在任何一个地方都看不到它们,那么它们
- are either filtered out in the settings: check your settings for Package Explorer (the Package Explorer bar, downwards menu arrow -> Filters...)
- or they were created externally and Eclipse haven't noticed them: Refreshyour project in this case.
- or they don't exist: right-click on the project, select New->Folderand input the path, e.g.
src/test/java
(not"Source Folder"). After you use Maven->Update Project...on the project, they will be automatically added as source folders, provided you have the default configuration.
- 要么在设置中被过滤掉:检查包资源管理器的设置(包资源管理器栏,向下菜单箭头 -> 过滤器...)
- 或者它们是在外部创建的而 Eclipse 没有注意到它们:在这种情况下刷新您的项目。
- 或者它们不存在:右键单击项目,选择新建->文件夹并输入路径,例如
src/test/java
(不是“源文件夹”)。在项目上使用Maven->Update Project... 后,它们将自动添加为源文件夹,前提是您具有默认配置。
Now, as I said, those folder will only be used as source if you preserved the default configuration in your POM
. If you defined other resources
and/or testResources
, those will be used instead. In general, Eclipse m2e synchronizes Eclipse's project source folder configuration with what's in your POM
.
现在,正如我所说,如果您在POM
. 如果您定义了 otherresources
和/或testResources
,则将使用它们。通常,Eclipse m2e 将 Eclipse 的项目源文件夹配置与POM
.
EDIT:maybe this is unclear - see those folders at the top? The ones labeled with the /-separated paths? These are your folders. These are the same folders that you would expect to find in main
and test
, just represented differently.
编辑:也许这不清楚 - 看到顶部的那些文件夹吗?用 / 分隔的路径标记的那些?这些是您的文件夹。这些是您希望在main
和 中找到的相同文件夹test
,只是表示方式不同。
回答by Chinmay Patel
I used to get the same problem, but solved it by pointing to the right jre used for the project.
我曾经遇到过同样的问题,但通过指向用于项目的正确 jre 解决了它。
Right click on the project properties java builpath see the jre selected edit it select alternate jre installed jre select the right one ok After changing right click on project>maven>update project
右击项目属性 java builpath 查看jre 选中编辑它选择alternate jre installed jre 选择正确的一个ok 更改后右键单击project>maven>update project
Hope it helps.
Attaching screen shot.
希望能帮助到你。附上屏幕截图。
回答by peja
I had the same problem, I changed my Eclipse project view from Package explorer to Project Explorer.
我遇到了同样的问题,我将 Eclipse 项目视图从包资源管理器更改为项目资源管理器。
回答by Bandham Manikanta
If you are looking for Simple/quicker way, you can follow this solution.
如果您正在寻找简单/更快的方式,您可以遵循此解决方案。
Right click on your project
.- Goto
> Build Path > Configure Build Path > Java Build Path
- Goto '
Source
' tab, there, you can see like<<your_project_name>>/src/main/java(missing)
. - Click on it and remove.
- Click on
Apply and Close
. - Now, right click on project and
>New > Source folder > add source folder "src/main/java"
.
Right click on your project
.- 去
> Build Path > Configure Build Path > Java Build Path
- 转到“
Source
”选项卡,在那里,您可以看到像<<your_project_name>>/src/main/java(missing)
。 - 单击它并删除。
- 单击
Apply and Close
。 - 现在,右键单击项目和
>New > Source folder > add source folder "src/main/java"
。
happy learning.
happy learning.
回答by vinsinraw
I had a similar issue when I checked out a web project from a github repo on my eclipse. src/main/java was directly inside the project root in Package Explorer. My expectation was that src/main/java be visible inside a source folder "Java Resources". There were few things which I did to achieve this.
当我从 eclipse 上的 github 存储库检出一个 web 项目时,我遇到了类似的问题。src/main/java 直接位于包资源管理器中的项目根目录中。我的期望是 src/main/java 在源文件夹“Java Resources”中可见。我做了几件事来实现这一目标。
- Right click on Project > Build Path > Configure Build Path..
- Select filter "Java Build Path" and click on Tab "Libraries" Verify your "JRE System Library". If it is not pointing to your latest JDK, then you can click on Edit Button and follow the subsequent dialog boxes to select most appropriate JDK home path in your system. Once done click Apply, Apply and Close, Finish to close all the associated open boxes for the current filter.
- Select filter "Java Compiler" and ensure your JDK Compliance points to correct JDK. Click Aapply
- Select filter "Project Facets". Ensure both Java and Dynamic Web Module is selected with correct version.
- Click Apply and Close.
- Source folder "Java Resources" gets created with src/main/java in it when viewed in Project Explorer.
- 右键单击“项目”>“构建路径”>“配置构建路径”。
- 选择过滤器“Java 构建路径”并单击“库”选项卡验证您的“JRE 系统库”。如果它没有指向您最新的 JDK,那么您可以单击“编辑”按钮并按照随后的对话框在您的系统中选择最合适的 JDK 主路径。完成后,单击应用、应用和关闭、完成以关闭当前过滤器的所有关联打开框。
- 选择过滤器“Java Compiler”并确保您的 JDK Compliance 指向正确的 JDK。点击应用
- 选择过滤器“项目构面”。确保 Java 和动态 Web 模块都选择了正确的版本。
- 单击应用并关闭。
- 在项目资源管理器中查看时,源文件夹“Java 资源”被创建,其中包含 src/main/java。
回答by Santosh budhe
I used this tutorial to create my maven web project http://crunchify.com/how-to-create-dynamic-web-project-using-maven-in-eclipse/and eclipse did not create src/main/java folder for me. When i tired to create the source folder src/main/java eclipse did not let me. So i created the folder outside eclipse in the project directly and then src/main/java appeared in eclipse.
我使用本教程创建了我的 maven web 项目http://crunchify.com/how-to-create-dynamic-web-project-using-maven-in-eclipse/并且 eclipse 没有创建 src/main/java 文件夹我。当我累了创建源文件夹 src/main/java eclipse 没有让我。所以我直接在项目中创建了eclipse之外的文件夹,然后在eclipse中出现了src/main/java。
回答by cohadar
This error happens when there are no files inside /src/main/java Just make some empty files inside and the problem will go away.
当 /src/main/java 中没有文件时会发生此错误,只需在其中创建一些空文件,问题就会消失。
A side note: lots of version control systems (mercurial for example) do not commit folders if there are no files inside.
旁注:如果里面没有文件,许多版本控制系统(例如mercurial)不会提交文件夹。
回答by DeviC3
After creating the project go to properties --> build path --> configure build path --> order and export tab and check jre and maven dependencies. You will then have the folder.
创建项目后,转到属性 --> 构建路径 --> 配置构建路径 --> 顺序和导出选项卡并检查 jre 和 maven 依赖项。然后,您将拥有该文件夹。
回答by vickyvirus
Right click on eclipse project go to build path and then configure build path you will see jre and maven will be unchecked check both of them and your error will be solved
右键单击 eclipse 项目转到构建路径,然后配置构建路径,您将看到 jre 和 maven 将被取消选中检查它们,您的错误将得到解决