I can't understand how to create folders and packages in Eclipse, specifically in the Package Explorer. Eclipse seems to create and represent the source folders and packages inconsistently.
A lot of this has to do with using the standard folder structure (src/main/java, src/main/test, etc.), and then having packages underneath them. Sometime Eclipse collapses the folders, with the packages underneath it, like this:
While other times, the folders are nested underneath each other, with each folder separate. Rather than a single "src/main/java" entry, it is nested into "src", "main", and "java" folders separately. Similarly, sometimes it doesn't show the packages, but actually shows the individual folders. For example, instead of showing "com.pluralsight.model", it has the nested folders for that package with "com", "pluralsight", and "model" separate.
Now I get that normally the actual folder structure in the file system is normally the individual folders (at least that is the convention, though you can set things up differently), as can be seen in the spring_sample folder structure in File Explorer:
But, if I create a src/main/java folder in another normal Java/Maven project, and then try to create a new package in that folder, I can't choose it in the "new/package" dialog box, and it creates the package in the root folder, rather than under src/main/java, and it doesn't show up as a package - it shows up as individual, nested folders. It doesn't matter where I put the source files that call out that package. See here:
So what's going on here? How can I create empty packages in Eclipse where I want them and get them to show up as either collapsed folders or as packages like in the "spring_sample" project shown above? Why do they show up as individually nested folders sometimes instead?




src/main/javashows that way because thejavafolder is a "source folder". Your second project doesn't seem to have any source folders defined. --- Notice how a package has an icon that is a yellow square with a big plus, and how a source folder has a icon that is an open folder with a package icon in it. Also notice howsrcandmainshow as normal folders towards the end in the first project, butjavais missing down there, because it is shown as a source folder up top.