Eclipse - How to “Change package declaration to …”

2019-02-01 21:56发布

I've just imported a large amount of source code into Eclipse and basically the package name is no longer valid (the code has been moved folders). Is there a way to select all the source code in the Package Explorer and hit a hotkey so that all package declarations are correctly resolved for me? I know you can do this with imports by selecting the source and hitting ctl-shift-o, but is also possible for the package declaration?

Update: Refactoring the packages doesn't work as I don't want to change the name or location of the packages, I just need to adjust the package declaration in the Java source code.

7条回答
beautiful°
2楼-- · 2019-02-01 22:49

For this particular problem (which usually comes with auto generated artifact files), I found a neat solution.

So if the issue is that your package declarations is "package abc;" in 200 files, and you want it to be "package com.aa.bb.cc.abc;"

Then in eclipse, Search->File for "package abc;" in required folder or pkg or whole workspace. Don't select Search option but select "Replace" and then put "package com.aa.bb.cc.abc;" when it asks for the replacement after search. Should do the trick.

查看更多
登录 后发表回答