Eclipse - How to "Change package declaration to ...." across an entire project

Viewed 38848

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 Answers

This should do the trick for you.

Import all your files into the default package first and then drag them into the new package, JDT will do the refactoring and change the package declarations across the project.

  • ALT+SHIFT+R add underscore at end of package name, hit ENTER twice
  • ALT+SHIFT+R delete the underscore, ENTER twice

Done if there are few packages.

Related