43

How can I make a child package inside a package in eclipse project explorer?

I already tried..

com.proj.test

then I create a new package

com.proj.test.child

to add a child package at package

com.proj.test,

but did not succeed

Nicholas K
  • 15,148
  • 7
  • 31
  • 57
user1907521
  • 431
  • 1
  • 5
  • 9
  • http://stackoverflow.com/questions/3915961/how-to-view-hierarchical-package-structure-in-eclipse-package-explorer The first answer solved this problem. –  Jan 01 '15 at 04:11

10 Answers10

91

To enable hierarchical visualization in the eclipse package explorer do these following steps:

In The Package Explorer View / View Menu (An arrow pointing down on top right) Go to Package Presentation and set type to Hierarchical.

Tom
  • 83
  • 2
  • 12
Guilherme Muniz
  • 1,265
  • 11
  • 12
21

What you did is correct, I assume you are using 'Project explorer' view, switch to hierarchical view to see content as child-parent : Window->Show View->Navigator

Pavel
  • 1,627
  • 15
  • 12
11

Right click on the package com.proj.test, new -> package and then write com.proj.test.child for the name.

I tried it just now and it works well.

Michaël
  • 3,679
  • 7
  • 39
  • 64
4

When you select "New Package" off the eclipse menu, the corresponding folder(s) will also be created automatically.

You don't have to define sub-packages one level at a time.

If You define a new package and enter the package name

com.coder.javapackage.innerone.etc

any missing elements in that package tree will also be created automatically.

Example from eclipse

This is just visual representation on the package. In reality they can sit in two different jars, but you should not be concerned about it, because jvm and loader internally handle that.

cagcak
  • 3,894
  • 2
  • 21
  • 22
4

I gave up on trying to reason with Eclipse as it seemed to completely ignore my hierarchal package representation setting, plus it was ignoring packages for some reason and refusing to compile as a result… I just made the folder hierarchy myself in Finder then imported it into Eclipse. That fixed everything.

sudo
  • 5,604
  • 5
  • 40
  • 78
  • If you don't have two child packages, it will continue displaying the package as `foo.bar` even in hierarchical view. If you add a `foo.baz` then it will display it correctly. – forresthopkinsa Dec 21 '16 at 20:29
3

In Project Explorer perspective View Menu -> Package Presentation -> Hierarchical . I hope it helps.

  • Can you explain that further? How does the View menu relate to creating a new package? – Nico Haase Apr 06 '19 at 10:46
  • If you do not set Hierarchical presentation on packages then thy will be instantiated as separate package. Add a new chilled package in perspective Project Explorer not Package Explorer. Thanks. – Jasmin Guberinic Apr 07 '19 at 14:09
  • Please add all such explanation to your answer, not to the comment section. Keep in mind that others should be able to learn from your answer – Nico Haase Apr 07 '19 at 18:22
2

I was able to change the "Package Presentation" option, which by default has the option "Flat" to "Hierarchical". This option is present in button "View menu", on "Project Explorer" perspective.

1

First create the parent package and then press the right click on the parent package select new package where you see new window will appear then write new package name beside the parent package with dot. Ex- test (this is parent package called test) test.model (this is child package called model) like this you can on and on to make more package like - test.model.modelOne Hope this will help someone.

Mjachowdhury
  • 85
  • 10
0

Right click on package parent and write complete name of child package is OK. But then to have a good graphical representation, you have to add a file in this child package... It's just refresh IHM (if you look folders of project, they already exist before this refresh). Eclipse does not refresh enough project window...

aeocom
  • 1
  • 1
0

If your project under "Project explorer" view then change it to "Navigator" . As follows

      Window->Show View->Navigator
      By doing this you will able to see packages as parent child hierarchy. 
Sachindra N. Pandey
  • 1,177
  • 17
  • 15