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

风格不统一 提交于 2019-12-12 11:34:27

问题


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?


回答1:


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 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




回答2:


Actually the better answer is:

  1. Go to the project-structure sub-window in IntelliJ.

  2. Create new package.

  3. Just drag and drop the file from the older location to the new location from the project-structure sub-window.



来源:https://stackoverflow.com/questions/38176751/how-to-create-a-sub-package-and-add-existing-files-intellij

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!