12

In eclipse, I would like to see packages as a folder structure rather than the flattened look provided by the Package Explorer default settings, is there a way to do this?

Tim Bender
  • 20,112
  • 2
  • 49
  • 58
CaptainForge
  • 1,365
  • 7
  • 21
  • 46
  • Whats a subpackage? You can highlight an existing package and select the new package icon on the run bar, in order to have it pre-populate the existing packages name. – Perception Apr 04 '13 at 02:00
  • @jahroy I understand that you are off-put by the OP's claim to having searched for an answer, but I think a down vote is enough. Why not just answer? Or do your own research and find the duplicate. – Tim Bender Apr 04 '13 at 02:06
  • @jahroy None of the things anyone is suggesting is actually creating a subpackage, I've tried it all already. I'm wanting to have the packages be folders that I put other packages in, but I've tried many methods. I've tried the ones on this page already. Before you downgrade a question, how about you look into what it's actually asking? Either my version of Eclipse is screwed up, or you people are misguided by what I'm asking. – CaptainForge Apr 04 '13 at 02:09
  • Before asking a question, maybe you should determine if your question is valid. I don't think you understand packages. – jahroy Apr 04 '13 at 02:34
  • @jahroy I understand that in the default Java library there are sub-packages (Example: superPackage.subPackage.anotherSub.class). And I found it rather reasonable to assume that Eclipse would have a convenient way of visualizing this. – CaptainForge Apr 04 '13 at 02:44
  • I apologize for that last comment. At the time it was extremely unclear what you were after. As always, it helps to add as much detail when asking a question ;-) When in doubt, thorough descriptions and/or screenshots always help. – jahroy Apr 04 '13 at 02:54

3 Answers3

25

Eclipse offers the Navigator view which will display your project in the way you are asking. To open this view select Window > Show View > Navigator.

Tim Bender
  • 20,112
  • 2
  • 49
  • 58
  • I've already tried all of these methods. Either my version of Eclipse is wacko or nobody is understanding what I'm wanting to do: I want to put a package INSIDE of another package. I've tried everything on this page already and nobody has given me a method that I'm yet to try. It HAS to be possible to put a package within another in the project explorer. – CaptainForge Apr 04 '13 at 02:15
  • Oh, lol... what you are talking about is the way Eclipse visualizes the packages. You might say that a package inside another is a "sub-package" but it isn't. It is really just another package. Eclipse will show you every package without having to expand nodes on a tree because it is way more convenient. Think about it, what you are asking would have just one tree node in the typical project explorer called `com` and to find the packages everyone would have to expand `com` then `example` then `www` then `my-package`... see how this would be annoying? – Tim Bender Apr 04 '13 at 02:37
  • This is all about _how things appear in the explorer_??? That has never been made clear... Maybe you can just explore packages using "_file view_" rather than "_project view_" (if such a thing exists in Eclipse). – jahroy Apr 04 '13 at 02:38
  • @jahroy yes it is, I'm working on a large project and it's confusing / annoying to have to shift through so many packages, I would much prefer to be able to put some within another. – CaptainForge Apr 04 '13 at 02:40
  • @Tim Bender I understand why you think this would be annoying, but I find it convenient. Is there a way to change how Eclipse visualizes the packages? – CaptainForge Apr 04 '13 at 02:40
  • Try `Window -> Show View -> Navigator`. It will allow you to navigate your source files like they appear on disk. I've always found this to be better than "_Project Explorer_" myself... It acutally helps you understand the way your project is structured on disk. You will probably want to expand the _src_ folder to find your packages. (the comment by @Perception suggested this 15 minutes ago) – jahroy Apr 04 '13 at 02:41
  • Yeah, `Navigator` will do the trick. I would wonder if certain parts of your application are not better suited as independent libraries to be imported as Jar files. Though I could imagine a problem like that with a particularly large web application. – Tim Bender Apr 04 '13 at 02:45
  • I agree with @JavaOverlord - I find the _Navigator_ view to be better than the _Project Explorer_ view (at least when dealing with their counterparts in NetBeans). – jahroy Apr 04 '13 at 02:57
  • Okay, I did a bunch of cleanup on this question to try to make it halfway decent. – Tim Bender Apr 04 '13 at 06:41
14

Select the first package in the package explorer. Press Alt-Shift-N to open the new item context menu. Click "Package."

Make sure that the new package name is a sub-package of the original package. For example, if your original package is com.example, the new package might be com.example.gui.


EDIT: If you want to see the nested packages, Eugene says that you can do this:

Package Explorer / View Menu (Ctrl-F10) / Package Presentation... / Hierarchical

Community
  • 1
  • 1
wchargin
  • 15,589
  • 12
  • 71
  • 110
  • I have tried this already and it did not work. It appears on the same "level" as its parent package. – CaptainForge Apr 04 '13 at 02:05
  • 1
    @MatthewPage - I think you are misunderstanding what a Java package is. If you want to see the packages in a hierarchical view, then use the Navigator view (Window->Show View->Navigator). – Perception Apr 04 '13 at 02:27
  • 1
    Your edit is what he needed i think. The hierarchical package presentation solved the problem for me. I think it's the right answer to this question. – Mr. Smith Dec 11 '14 at 22:34
0

Click on three dots on project explorer toolbar -> Package representation -> select
Hierarchical

[Eclipse Image][1] [1]: https://i.stack.imgur.com/qTGqm.png