Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to rename multiple Java packages in Eclipse with a single command?

Tags:

java

eclipse

My Java project structure in Eclipse looks like this:

myproject
    src/main/java
        com.mypackage.mysubpackage1
        com.mypackage.mysubpackage2
        com.mypackage.mysubpackage3
        com.myotherpackage.mysubpackage1
        com.myotherpackage.mysubpackage1
        com.myotherpackage.mysubpackage1

But I've decided that mypackage is not a good name for the packages in the first group. Instead I would like to rename them to mynewpackage so that my package structure would look like this:

myproject
    src/main/java
        com.mynewpackage.mysubpackage1
        com.mynewpackage.mysubpackage2
        com.mynewpackage.mysubpackage3
        com.myotherpackage.mysubpackage1
        com.myotherpackage.mysubpackage1
        com.myotherpackage.mysubpackage1

The only way I am aware of, with my limited knowledge of Eclipse, is to right-click on each subpackage and choose Refactor -> Rename.

But because the package list is quite long, I am rather hoping there is a single command that I am not aware of that would allow me to rename all of these packages in bulk.

like image 849
Carlsberg Avatar asked Sep 01 '10 10:09

Carlsberg


People also ask

How do I Rename multiple files in Eclipse?

Right click on file name -> Refactor -> Rename -> Use the new name then press enter.

Can you Rename packages in Eclipse?

Right-click the package you want to move, and select " Refactor/Rename..." -- NOT " Move "! Modify the name of the package to reflect its desired new position in the package hierarchy, e.g. Prepend any new parent package name(s) if you are moving the package to downwards in the package hierarchy.

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 change the name of my java project in Eclipse?

To rename the project, simply right-click the project and select "Refactor/Rename...". Fill in the new name and click OK.


2 Answers

There is but it's not obvious. First, you must switch from "flat" to "hierarchical" view (see the menu in the "Package Explorer" under "Package Presentation").

Now you should get a single package entry in the view which you can select and rename.

like image 184
Aaron Digulla Avatar answered Sep 17 '22 18:09

Aaron Digulla


On Eclipse: Select your package and press Alt + Shift + R and type the new package name.

First check, the Projects Presentation must be Hierarchical.

Regards.

like image 38
Saledwin Avatar answered Sep 18 '22 18:09

Saledwin