Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming packages in Eclipse

In Eclipse's "Package Explorer", let's say I have a list of packages like this:

  • com.dog
  • com.cat
  • com.frog

If I want to rename the "com" part of the package structure to be "animal", then I could select each package (above) and perform a refactor > rename.

If I have many packages that start with "com", that process may take a while. Is there an easy way to rename the "com" package name without having to individually rename each package in the Package Explorer? or removing those packages from the build path before renaming?

I tried going to the "Navigator" pane where it displays the folders in a tree structure but I am not given the rename capability.

like image 686
digiarnie Avatar asked Aug 31 '09 04:08

digiarnie


People also ask

Can we Rename package in Java?

Rename a package In the Project tool window, click Project and select Packages from the list. IntelliJ IDEA lists all the packages in your project. Right-click the package you want to rename and from the context menu, select Refactor | Rename ( Shift+F6 ).

How do I Rename a folder in Eclipse?

Right-mouse click in the repository view on the folder you want to rename and choose Rename path process. Rename the folder. Invoke "Add to Workspace". Perform synchronizing the Eclipse project folder and change will be reflected.


1 Answers

By default empty parent packages are hidden in the package explorer, if you modify the Filters... in the Package Explorer to uncheck Empty Parent Packages (third from top in second screenshot) you'll be able to see the empty packages.

package explorer filters

filters view
(source: eclipse.org)

You can then rename the com package and check the Rename subpackages option to force all child packages to be renamed.

rename package
(source: eclipse.org)

Then when you're done reapply the filter to hide all those empty packages again.

like image 90
Rich Seller Avatar answered Sep 19 '22 09:09

Rich Seller