How to make child packages in packages on Eclipse?

Normally, if you separate each package component with dots (.), it should create intermediate entries.

Try create a new package with the following test case:

  • com.foobar.example
  • com.foobar.test
  • com.foobar.example.a

And Eclipse should do the tricks.

If however, you are stuck with finding those empty packages, perhaps you should simply play with the Package Explorer options: the Java filters is especially useful, and there might be an option enabled by default which would filter/hide empty package.

You also have Package presentations.

Since an image is better than long lines of text:

Eclipse

  1. Click the arrow to open the presentations options (see the Package Explorer on the left)
  2. The Filters options does have filters which might hide empty parent packages.
  3. The hierarchical package presentation behave like the Explorer left pane.

A folder-like hierachy is implicitly created by the package names in Java. Lets say you have a package com.company and you want a sub-package in that package. Then you have to create a package with the name com.company.product. It is not done by creating a package with the name product while com.company is selected!


When creating a new package you can create a hierarchy by simply separating your parent folder with child folder with a dot '.'. So if you want to create a sub package of foo.bar you have to create a package with name foo.bar.myfoo. Eclipse will do the rest.

If you instead want to visualize the folder type hierachy as here:

enter image description here

you can click in the little arrow top left of the project explorer view menù and go to Package Presentation > Hierarchical.

Tags:

Eclipse