33

Should renaming a project in Eclipse also rename project folder on file system ?

My project file system name remains the same even when I rename the file on Eclipse.

Should I manually rename the project on the file system to same on Eclipse ?

blue-sky
  • 51,962
  • 152
  • 427
  • 752

7 Answers7

51

It appears that renaming a project will only rename the underlying filesystem directory if the project was created with the "Use Default Location" checkbox selected (meaning the project is created in the workspace directory). If you create a project and specify a custom location outside the workspace, renaming that project in Eclipse does not rename the project's host directory. In that case, you'll probably want to:

  1. Rename the project in Eclipse (which will update any internal references and the .project file)
  2. Remove the project from your Eclipse Workbench view (making sure that the "Delete file contents" option is NOT selected in the delete confirmation dialog).
  3. Rename the project's directory in your filesystem.
  4. Import the project back into your Eclipse workspace.

I was surprised to learn this (I tested it with Eclipse 3.7), but it seems to be logical to me. The idea is that projects in the workspace folder are considered to be "under Eclipse control" as opposed to projects that are located in arbitrary places on your filesystem.

E-Riz
  • 31,431
  • 9
  • 97
  • 134
  • Yes, project im trying to rename is outside Eclipse workspace. thanks for this. – blue-sky Feb 10 '12 at 22:56
  • 1
    This also means that even if it was originally created in the workspace, sharing it with a Git repository (right-click > Team > Share Project) will cause subsequent renames not to affect the underlying filesystem directory. – wchargin Feb 08 '14 at 16:19
  • In netbeans it works simply using `renamed-name` tag and it does not rename on folder but eclipse we should rename from folder itself. – Yubaraj Sep 08 '15 at 06:52
  • 'Package Explorer' view -> right click project -> Refactor -> *Move*. No need to remove and reimport. – user136036 Jan 10 '20 at 22:50
  • -- I dont like this inconsistency in Eclipse... Why isn't there is an option to choose whether "rename project name and also rename the folder name"... -- This also makes renaming nest projects troublesome. -- (I have to `F2` to rename project name, then `alt shift v` to rename folder name (move to the same location to keep the name consistent).) – Nor.Z May 06 '22 at 04:35
8

Use Refactor to rename the project name. It will rename the file/folder in filesystem as well.

Refactoring in Eclipse

Jayy
  • 2,368
  • 4
  • 24
  • 35
  • 9
    " It will rename the file/folder in filesystem as well" No it does'nt, at least not in my version of Eclipse - 3.7.1. As far I know renaming a project in Eclipse is same as using Refactor to rename. – blue-sky Feb 10 '12 at 16:48
  • These are my eclipse details Version: 3.4.1 Build id: M20080911-1700. I tried as shown above and it works. – Jayy Feb 10 '12 at 16:53
  • 1
    That only works if the project was originally created using the default location (directly in the workspace folder). See my answer above. – E-Riz Feb 11 '14 at 03:23
  • 1
    In Eclipse Oxygen (4.7) refactoring the project name via "Rename" _does not_ rename the folder in the underlying filesystem. – davidA Sep 30 '17 at 20:47
7

Menu -> Refactor -> Move... (Shift + Alt + V).

In this window you can change name of the folder name and also change the path completely.

luboskrnac
  • 23,973
  • 10
  • 81
  • 92
2

If the folder name is important, then change it manually. Keep in mind that you will have to re-open or re-import the the project into eclipse. After you rename the folder, Eclipse won't know where to find it.

Zac B
  • 3,796
  • 3
  • 35
  • 52
1

In Eclipse Oxygen (4.7) the Move option is greyed and renaming the project does not rename the directory. However, if you switch to the Navigator view (may need to find it under Window > Show View > Navigator) the Move option will be available and it will rename the project's directory.

This is a lot faster than having to recreate the project or re-import it.

davidA
  • 12,528
  • 9
  • 64
  • 96
1

If your project is a Maven project to rename, do steps as followed:

  1. Open Context Menu on your project > Refactor > Rename Maven Artifact.
  2. Change Group or ID.
  3. Check "Rename Eclipse project in Workspace".
  4. press OK button.
  5. Update maven project by Context Menu > Maven > Update Project.
Shadyar
  • 709
  • 8
  • 16
0

Using eclipse Neon 4.6.3, renaming does not work. You will have to do what E-Ritz said in his answer.

It is also worth mentioning that if you are importing a project as a Maven project (via Import... -> Existing Maven Projects), the project name will be taken from the pom.xml rather than the folder. So you should also change the <name>my-project-name</name> part of the pom

Urosh T.
  • 3,336
  • 5
  • 34
  • 42