Eclipse: change the name of an existing package with classes inside

In Eclipse, can I change the name of a package if it has a name (default package) and contains classes inside it?

+43
java eclipse
Apr 15 2018-12-12T00:
source share
6 answers

In the version of Eclipse that I use (Indigo service release 1), the Rename option is not suitable for the default package (unlike other packages), but if you select all classes, right-click and select Move to You could put them in a new package.

(As far as I can tell, the Rename option is for renaming classes without changing their package, but Move definitely works for moving between packages.)

Screenshots of the process:

initial situation

Before

Select all classes and show the Refactor part of the context menu.

enter image description here

Select "Move", click "Create Package" and enter a name (mypackage in this case)

Move dialog

Final result

After

Alternatively, if you want to move them to an existing package, you can simply drag and drop the classes.

For those who offer Refactor -> Rename on the package, here is a screenshot showing what doesn't work on my machine:

No rename option

+80
Apr 15 2018-12-12T00:
source share

Yes.

Or just right-click the class and select "Refactor-> Rename" or paste the appropriate package foo.bar at the top and use Ctrl-1 for a quick fix.

+8
Apr 15 2018-12-12T00:
source share

Create a new package inside the SRC folder, and then drag the class file into the new package. So the default package name changes

+1
Apr 19 '16 at 13:19
source share

Another option is to go to the src folder in the corresponding project folder in the workspace and create a new folder. Name this folder as any package name you want and put all your .java files in this folder. Update eclipse, close the .java files and open a new location.

0
Nov 19 '13 at 7:17
source share

I created a new package under the "Java Package" with the correct name. Then drag the default source files. IDE will ask for refactoring; then continue with it. The default package has disappeared and the source files have been updated.

0
May 13 '14 at 19:14
source share

Step 1. Create a new package in the same project.

Step 2. Press and hold classes from the standard package to the new package.

0
Jun 22 '19 at 19:49
source share



All Articles