Java 如何在 Intellij Idea 12 中重命名/移动项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18493379/
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-08-12 08:31:18  来源:igfitidea点击:

How to rename / move a project in Intellij Idea 12?

javaintellij-ideakotlinide

提问by sheidaei

As stated hereone can change the name of a project. However, it only changes the name of the project and it will not change the folder structure.

正如此处所述您可以更改项目的名称。但是,它只会更改项目的名称,不会更改文件夹结构。

As an example if your project is called sample1 and it resides ~/user1/development/IdeaProjects/sample1, the folder location won't be changed to ~/user1/development/IdeaProjects/sample2 if one changes the project name to sample2.

例如,如果您的项目名为 sample1 并且它位于 ~/user1/development/IdeaProjects/sample1,则如果将项目名称更改为 sample2,文件夹位置将不会更改为 ~/user1/development/IdeaProjects/sample2。

采纳答案by sheidaei

It seems that one has to right click on the project (after following the instructions to rename the Project), then choose Refactor -> Move to relocate project to the new location. I didn't find any solution to rename and move a project at once.

似乎必须右键单击项目(按照说明重命名项目后),然后选择 Refactor -> Move 将项目重新定位到新位置。我没有找到任何可以立即重命名和移动项目的解决方案。

回答by Mohammadreza Khatami

click on your project file,which is you want to move and then push F6

单击您要移动的项目文件,然后按 F6

回答by snowbound

  1. Close IntelliJ
  2. Rename the folder in Explorer (Windows) / Finder (OSX)
  3. Open IntelliJ
  4. Import Project from Dialog, or File -> Import Project
  5. Select the folder with the new name
  6. Follow the dialogues
  1. 关闭 IntelliJ
  2. 重命名资源管理器 (Windows) / Finder (OSX) 中的文件夹
  3. 打开 IntelliJ
  4. 从对话框或文件导入项目 -> 导入项目
  5. 选择具有新名称的文件夹
  6. 关注对话

回答by Dawid Naczke

  1. Right click on project, then Refactor -> Rename...(shift+F6), set desired name
  2. Close IntelliJ
  3. Rename directory in your filesystem to your desired name
  4. In startup dialog select Open(or File -> Open... in main window)
  5. Please select renamed project directory
  1. 右键单击项目,然后重构 -> 重命名...(shift+F6),设置所需的名称
  2. 关闭 IntelliJ
  3. 将文件系统中的目录重命名为您想要的名称
  4. 在启动对话框中选择Open(或File -> Open... 在主窗口中)
  5. 请选择重命名的项目目录

Enjoy, it work's for me!

享受,它对我有用!

回答by Joman68

If it is a gradle project, instead of renaming it using Refactor->Rename:

如果它是一个 gradle 项目,而不是使用Refactor->Rename 重命名它:

  • set the rootProject.namevariable in the settings.gradlefile to the new project name.
  • reimport the project. Hit the 'Refresh all Gradle Projects' button in the Gradle Tool Window.
  • settings.gradle文件中的rootProject.name变量设置为新的项目名称。
  • 重新导入项目。点击 Gradle 工具窗口中的“刷新所有 Gradle 项目”按钮。

Then follow steps 2 to 5 in @Dawid's answer.

然后按照@Dawid 的回答中的步骤 2 到 5 进行操作。

To remove the old project from IntelliJ's list of managed projects:

从 IntelliJ 的托管项目列表中删除旧项目:

  • select File->Open Recent->Manage Projects..
  • click the 'x' next to the old project name
  • 选择文件->打开最近的->管理项目..
  • 单击旧项目名称旁边的“x”

回答by Yogesh Umesh Vaity

After renaming the project folder of a Kotlin project in IntelliJ, using the Import Project option as suggested in the other answers created module related problems for me. I was not able to select Main class in the Run dialogue. To solve this, I used Create New Projectoption. It doesn't delete your project files.

在 IntelliJ 中重命名 Kotlin 项目的项目文件夹后,使用其他答案中建议的导入项目选项为我创建了与模块相关的问题。我无法在 Run 对话框中选择 Main 类。为了解决这个问题,我使用了Create New Project选项。它不会删除您的项目文件。

So to rename the folder, first create a copy of your project for safety and then follow these steps:

因此,要重命名文件夹,请先创建项目的副本以确保安全,然后按照以下步骤操作:

  1. Close IntelliJ.
  2. Go to file explorer and manually rename the folder.
  3. Open IntelliJ.
  4. Choose the option Create New Project
  5. Select your desired language/framework e.g. Kotlin, click Next
  6. For Project Name, specify your desired project name. Maybe same as folder name.
  7. For Project Location, choose the folder that you manually renamed.
  8. Click Finish, IntelliJ will ask if you want to overwrite .ideaand .imlfiles. Click Yesfor both.
  1. 关闭 IntelliJ。
  2. 转到文件资源管理器并手动重命名文件夹。
  3. 打开 IntelliJ。
  4. 选择选项 Create New Project
  5. 选择您想要的语言/框架,例如Kotlin,单击Next
  6. 对于Project Name,指定所需的项目名称。可能与文件夹名称相同。
  7. 对于Project Location选择您手动重命名的文件夹
  8. 单击Finish,IntelliJ 会询问您是否要覆盖.idea.iml文件。单击Yes两者。

Hope that helps.

希望有帮助。

回答by Mitch Greene

  1. Go to Filethen Project Structure
  2. Under Project Settings -> Projectmake sure that you change the project name.
  3. Then under Project Settings -> Moduleschange the name there as well.
  4. Restart Intellij
  5. Use your File Explorer to confirm that the project/modules have been renamed.
  1. File然后Project Structure
  2. Project Settings -> Project确保您更改项目名称下。
  3. 然后在Project Settings -> Modules那里更改名称。
  4. 重启 Intellij
  5. 使用文件资源管理器确认项目/模块已重命名。

回答by Pallavi Singh

Close IntelliJ 
Rename the folder in Explorer (Windows) / Finder
(OSX)   
Open IntelliJ Import Project from Dialog, or File -> Import
Project     
Select the folder with the new name 
further additional steps might be required if you see your module named
as  new_modulename[parent module/old module name],
then update   
settings.gradle with new name  and reimport

回答by 1234ru

For JetBrains v. 2019.2(September 2019):

对于 JetBrains v. 2019.2(2019 年 9 月):

To move project directory without changing it's name:

要移动项目目录而不更改其名称:

  1. Press Alt+1to open project structure

    • Right click on project directory
    • Go to File -> Refactor -> Move directory

    OR

    • Left click on project directory
    • Press F6

    Specify target parent directory and hit OK.

  1. Alt+1打开项目结构

    • 右键单击项目目录
    • 转到文件 -> 重构 -> 移动目录

    或者

    • 左键单击项目目录
    • F6

    指定目标父目录并点击确定。

To rename project directory:

重命名项目目录:

  1. Press Alt+1to open project structure

    • Right click on project directory
    • Go to File -> Refactor -> Rename...

    OR

    • Left click on project directory
    • Press Shift+F6
  2. Select Rename directory(actually it's already selected) and hit OK.

  3. Specify new directory name.

  1. Alt+1打开项目结构

    • 右键单击项目目录
    • 转到文件 -> 重构 -> 重命名...

    或者

    • 左键单击项目目录
    • Shift+F6
  2. 选择重命名目录(实际上它已经被选中)并点击确定。

  3. 指定新目录名称。

If you need both to move project directory and to change it's name, then do the steps one after another.

如果您需要移动项目目录并更改其名称,请一个接一个地执行这些步骤。

After you've done renaming/moving, close the projectand remove it from the recent projects list (it became non-functional and you won't need it anymore there).

完成重命名/移动后,关闭项目并将其从最近的项目列表中删除(它变得不起作用,您将不再需要它)。

Then hit "Open" and find the project directory at it's new location. Now you have your project directory moved!

然后点击“打开”并在新位置找到项目目录。现在你已经移动了你的项目目录!

The last two steps should be done with a command like Edit project or something like that, where you can directly specify project directory, but as there is no such command, you need to remove project and reopen it at it's new location instead.

最后两个步骤应该使用像 Edit project 或类似的命令来完成,您可以在其中直接指定项目目录,但由于没有这样的命令,您需要删除项目并在新位置重新打开它。

回答by Jeypi

A work-arround for this, if you get an error when click "projectPackage" -> Refactor -> Move, is to close Intellij, move the folder manually, and then in:

对此的解决方法是,如果在单击“projectPackage”-> 重构-> 移动时出现错误,请关闭 Intellij,手动移动文件夹,然后在:

C:\Users\user.name\ .IntelliJIdea2019.1\config\options

C:\Users\user.name\ .IntelliJIdea2019.1\config\options

edit the file recentProjects.xml like this, with you new path, save and close, re-open jetbrains ide and it's done.

像这样编辑文件recentProjects.xml,使用新路径,保存并关闭,重新打开jetbrains ide,就完成了。

configfile

配置文件