67

I'm wondering why I can't see following folders in src node in Package Explorer

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).

Maybe I can configure Eclipse somehow ?


enter image description here enter image description here enter image description here

Community
  • 1
  • 1
Sebastian Dusza
  • 2,470
  • 2
  • 30
  • 54

20 Answers20

142

I have solved this issue by below steps:

  1. Right click the Maven Project -> Build Path -> Configure Build Path
  2. In Order and Export tab, you can see the message like '2 build path entries are missing'
  3. Now select 'JRE System Library' and 'Maven Dependencies' checkbox
  4. Click OK

Now you can see below in all type of Explorers (Package or Project or Navigator)

src/main/java

src/main/resources

src/test/java
Lucky
  • 16,787
  • 19
  • 117
  • 151
Ranjith Sekar
  • 1,892
  • 2
  • 14
  • 18
62

Eclipse filters out folders that are marked as source from the "raw" folder path. That is, they are visible only as source folders:

example project

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: Refresh your project in this case.
  • or they don't exist: right-click on the project, select New->Folder and 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.

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.

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.

mikołak
  • 9,605
  • 1
  • 48
  • 70
  • Thx. I checked Package Explorer filter settings and I don't see any filter that would cause this behaviour. These directories exist in file system. I'm using default maven configuration that comes with Spring Tool Suite. – Sebastian Dusza Sep 16 '13 at 13:36
  • 1
    @Seba : did you refresh the project? – mikołak Sep 16 '13 at 13:49
  • 2
    yes. It seems that Project Explorer view behaves the way I wanted. – Sebastian Dusza Sep 16 '13 at 14:16
  • 1
    @Seba : sure, but it's a kludge in the long run - it shows more stuff than you usually need. If you're happy with it, OK, but otherwise can you edit in screenshots of your *Package Explorer* view + the *Filters* view + the *SpringSource->Global Preferences* view? – mikołak Sep 16 '13 at 16:46
  • It would be fantastic if Package Explorer could be fixed. I'll send those screenshots tomorrow. Thanks for help :-) – Sebastian Dusza Sep 16 '13 at 20:21
  • 1
    @Seba : you can thank me **if** I manage to solve your problem ;). – mikołak Sep 16 '13 at 21:19
  • Screenshots uploaded. Tell me if you need other screens. – Sebastian Dusza Sep 17 '13 at 11:34
  • 1
    @Seba : err, that looks fine to me. Those nodes exist as **source folders, at the very top of your project - the first four items, specifically**. My answer explains why it's this that way: they're treated as source folders by Eclipse (correctly), and **Eclipse shows source folders as direct children of the project, with their full relative path**. Could you clarify what specifically you find incorrect in this setup? – mikołak Sep 17 '13 at 11:50
  • Thats ok. I'm just wondering how to display those folders under src tree where they are hidden right now. – Sebastian Dusza Sep 19 '13 at 11:16
  • 1
    @Seba : ah, that's different. Can you clarify why do you want to show them in that location (in addition, I assume, to the standard)? – mikołak Sep 19 '13 at 16:07
  • I develop Spring based apps and it seems more clear to me when I can see full directory structure under src. No big deal :) – Sebastian Dusza Sep 20 '13 at 11:59
  • @Seba : well, apparently it seemed more clear this way for the SpringSource guys ;). I've searched some more for some settings out of curiosity, but no dice. And it makes sense - having it in two places would be confusing (which path to expand when using Linking with Editor?) and having it in one place, but non-standard, would confuse most Eclipse-using devs. – mikołak Sep 20 '13 at 12:11
22

I used to get the same problem, but solved it by pointing to the right jre used for the project.

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

Hope it helps. Attaching screen shot.enter image description here

Chinmay Patel
  • 430
  • 6
  • 12
  • 3
    I faced this as it's pointing it to JRE 1.5 . When i changed the same to JRE 1.8 , and update the Maven project , the folders created automatically. Thank you. – srinivas Oct 27 '15 at 07:53
15

If you are looking for Simple/quicker way, you can follow this solution.

  1. Right click on your project.
  2. Goto > Build Path > Configure Build Path > Java Build Path
  3. Goto 'Source' tab, there, you can see like <<your_project_name>>/src/main/java(missing).
  4. Click on it and remove.
  5. Click on Apply and Close.
  6. Now, right click on project and >New > Source folder > add source folder "src/main/java".

happy learning and do not forget to upvote :)

Bandham Manikanta
  • 1,858
  • 21
  • 21
11

I had the same problem, I changed my Eclipse project view from Package explorer to Project Explorer.

Lucky
  • 16,787
  • 19
  • 117
  • 151
peja
  • 866
  • 10
  • 19
5

After 2 hours of trying everything...

Just go on window -> show view -> project explorer and in project explorer you can view of all files solution

Nicolas
  • 2,321
  • 4
  • 21
  • 32
David Bister
  • 61
  • 1
  • 6
  • Nice one-liner, as simple as possible. I'm a 10 years experienced Java developer and still forget to switch between the Package Explorer and Project Explorer. And welcome to Stackoverflow community! – Levent Divilioglu Dec 04 '21 at 00:41
3

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.

  1. Right click on Project > Build Path > Configure Build Path..
  2. 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.
  3. Select filter "Java Compiler" and ensure your JDK Compliance points to correct JDK. Click Aapply
  4. Select filter "Project Facets". Ensure both Java and Dynamic Web Module is selected with correct version.
  5. Click Apply and Close.
  6. Source folder "Java Resources" gets created with src/main/java in it when viewed in Project Explorer.
vinsinraw
  • 2,003
  • 1
  • 16
  • 18
3

Navigate > Show In > Package Explore

Mirac Bektas
  • 115
  • 1
  • 2
2

Right click the Maven Project -> Build Path -> Configure Build Path Go to 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

2

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 Now you can see below in all type of Explorers (Package or Project or Navigator)

Saddam Hussain
  • 146
  • 1
  • 6
1

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.

Santosh budhe
  • 67
  • 1
  • 12
1

I was not able to see the build path option in the properties as well. Also the

src/main/java

was not visible in Project Explorer. below solution worked for me

  1. Go to Project root
  2. Select "Project facets" from Properties
  3. Check "Java"

This fixes the issue

Abdul Mohsin
  • 1,253
  • 1
  • 13
  • 24
1

If none of the answers worked for you. You might be in the wrong "Window". I was in "Package explorer" and switching to "Project Explorer" showed me the folders.

smooth_smoothie
  • 1,319
  • 10
  • 27
  • 40
1

Right click on the project > Build Path > Configure Build Path > Source > Add Folder > Select src/main/java > apply and close > refresh the project. enter image description here

AritraDB
  • 315
  • 4
  • 13
0

This error happens when there are no files inside /src/main/java Just make some empty files inside and the problem will go away.

A side note: lots of version control systems (mercurial for example) do not commit folders if there are no files inside.

cohadar
  • 4,709
  • 2
  • 20
  • 21
0

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.

DeviC3
  • 67
  • 1
  • 8
0

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

  • Welcome to SO, your input is appreciated. Please expand your answer a bit according to the [guidelines](https://stackoverflow.com/help/how-to-answer) – B--rian Nov 07 '19 at 07:41
0

My problem was kind of the same at first and then a little different in the sense that when /java folder showed up, it was deep down in a nested folder somewhere in src/main/resources/java.

Initallially the problem was being in the Package Explorer and not in the Project Explorer as many people have talked about. So,

  • a. right-click on your project root
  • b. show in, and select Project Explorer

However, the main problem was I missed to notice a checkbox at the second step of Maven Project Creation from the wizard. That got me created a complicated structure and not a clean direct one.

enter image description here

Once I marked it checked I got a clean project structure as what asked.

Iqra.
  • 685
  • 1
  • 7
  • 18
0

I was also facing the issue but I open POM xml file and keep it open. Wait for some time till maven read pom then Automatically it will come.

0

I tried all the solutions mentioned in this post but none of them worked for me.

The solution for me was to go to build-path and then into Source tab. I found src/main/java folders present there and there was no error. I double clicked on this folder and a window opened like this: enter image description here



Do not make any change and click on Finish. The folders will appear suddenly.

Eatsam ul haq
  • 317
  • 1
  • 12