在 Eclipse 中重命名项目是否也应该重命名文件系统上的项目文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9231270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 20:53:53  来源:igfitidea点击:

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

eclipsem2eclipse

提问by blue-sky

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

在 Eclipse 中重命名项目是否也应该重命名文件系统上的项目文件夹?

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

即使我在 Eclipse 上重命名文件,我的项目文件系统名称也保持不变。

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

我应该在 Eclipse 上手动将文件系统上的项目重命名为相同吗?

回答by E-Riz

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 notrename the project's host directory. In that case, you'll probably want to:

如果项目是在选中“使用默认位置”复选框的情况下创建的(意味着项目是在工作区目录中创建的),那么重命名项目似乎只会重命名基础文件系统目录。如果您创建一个项目并在工作区之外指定一个自定义位置,则在 Eclipse重命名该项目不会重命名该项目的宿主目录。在这种情况下,您可能想要:

  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 NOTselected in the delete confirmation dialog).
  3. Rename the project's directory in your filesystem.
  4. Import the project back into your Eclipse workspace.
  1. 在 Eclipse 中重命名项目(这将更新任何内部引用和 .project 文件)
  2. 从您的Eclipse工作台视图中的项目(确保“删除文件内容”选项不是在删除确认对话框中选择)。
  3. 重命名文件系统中的项目目录。
  4. 将项目导入回 Eclipse 工作区。

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.

我很惊讶地了解到这一点(我用 Eclipse 3.7 对其进行了测试),但这对我来说似乎是合乎逻辑的。这个想法是工作区文件夹中的项目被认为是“在 Eclipse 控制下”,而不是位于文件系统上任意位置的项目。

回答by Jayy

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

使用 Refactor 重命名项目名称。它也会重命名文件系统中的文件/文件夹。

Refactoring in Eclipse

在 Eclipse 中重构

回答by luboskrnac

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

菜单 -> 重构 -> 移动...(Shift + Alt + V)。

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

在此窗口中,您可以更改文件夹名称的名称,也可以完全更改路径。

回答by Zac B

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.

如果文件夹名称很重要,则手动更改它。请记住,您必须重新打开项目或将项目重新导入 Eclipse。重命名文件夹后,Eclipse 将不知道在哪里可以找到它。

回答by davidA

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.

在 Eclipse Oxygen (4.7) 中,移动选项是灰色的,重命名项目不会重命名目录。但是,如果您切换到 Navigator 视图(可能需要在 Window > Show View > Navigator 下找到它),Move 选项将可用,它将重命名项目的目录。

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

这比重新创建项目或重新导入项目要快得多。

回答by Urosh T.

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

使用 eclipse Neon 4.6.3,重命名不起作用。你将不得不按照 E-Ritz 在他的回答中所说的去做。

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

还值得一提的是,如果您将项目作为 Maven 项目(通过Import... -> Existing Maven Projects)导入,则项目名称将取自pom.xml而不是文件夹。所以你也应该改变<name>my-project-name</name>pom的部分