Reputation: 354
I have recently started coding on Eclipse for Minecraft Bukkit plugins, and I have been going fine with it. Recently, I've been trying to make a child package into a package, but if I try New > Package, then it makes a package separate to my main package. I am a beginner, so please make instructions simple. Is there anything else I can try?
Upvotes: 19
Views: 50870
Reputation: 1
For Eclipse Version 2020-09: To create sub-package we can directly go inside the eclipse-workspace and in the package where we want to create a sub-package and inside that we can create a new folder and then click on the three dots icon on the right side of the Package Explorer and select the Hierarchical option inside the package presentation option. We can then refresh the project and the new sub-packages will be reflected.Below is the image for reference Subpackage
Upvotes: 0
Reputation: 716
For eclipse Version: 2019-03 (4.11.0) Build id: 20190314-1200
I found it easier to create the desired package path along with the new class I wanted to exist at the new package path.
From within the Project Explorer view, right click on the corresponding project to create a New Class.
Then on the class creation popup I fill in the corresponding package field as I please to build out the new path as desired, along with the new class to sit in that new path.
Upvotes: 2
Reputation: 1454
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:
you can click in the little arrow top left of the project explorer view menù and go to Package Presentation > Hierarchical.
Upvotes: 8
Reputation: 11949
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:
Upvotes: 58
Reputation: 39631
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!
Upvotes: 4