Supun Wijerathne Supun Wijerathne - 3 months ago 28
Java Question

How to create a sub-package and add existing files intellij?

I have my project structure something like this.

| |
| |

But I want to change it into this one.

| |
| |

Can anyone tell me the preffered way to do that with intellij preserving all dependencies and usages?


There are two ways (AFAIK)

Method One

  1. Right click the class in the project explorer and Refactor -> Move or Select the Class in the project explorer press F6

  2. Then select To Package enter the new package name and press Refactor button.

Method Two

Just change the package statement in from package daos; to package daos.readers;, then you will see red line under the package statement, place the cursor on the statement then do ALT+ENTER then select 'Move package to daos.readers'. This method only changes the package but does not update the usages