I have my project structure something like this.
|--daos
| |
| |--MyDBReader.java
But I want to change it into this one.
daos
|
|--readers
| |
| |--MyDBReader.java
Can anyone tell me the preffered way to do that with intellij preserving all dependencies and usages?
From the main menu, select File | New | Module from Existing Sources. In the dialog that opens, specify the path the . iml file of the module that you want to import, and click Open. By doing so, you are attaching another module to the project without physically moving any files.
IntelliJ IDEA suggests to import single classes by default. You can change the settings to import entire packages instead. In the Settings/Preferences dialog ( Ctrl+Alt+S ), select Editor | Code Style | Java | Imports. Clear the Use single class import checkbox, and apply the changes.
There are two ways (AFAIK)
Method One
Right click the class in the project explorer and Refactor -> Move
or Select the Class in the project explorer press F6
Then select To Package
enter the new package name and press Refactor
button.
Method Two
Just change the package statement in MyDBReader.java 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
Actually the better answer is:
Go to the project-structure sub-window in IntelliJ.
Create new package.
Just drag and drop the file from the older location to the new location from the project-structure sub-window.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With