Java Eclipse 更改工作区和目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21717609/
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
Eclipse changing workspace and directory
提问by krato
I am not that used to changing workspaces in Eclipse, in fact, I only have one workspace. But right now, there is a need to change workspace and organize different projects but I don't know how to do it.
我不太习惯在 Eclipse 中更改工作区,事实上,我只有一个工作区。但是现在,需要更改工作区并组织不同的项目,但我不知道该怎么做。
I saw something about refactoring and simply importing projects but I don't want the outcome of that.
我看到了一些关于重构和简单导入项目的内容,但我不想要这样的结果。
Currently, I have C:\Users\krato\workspace\
as my default workspace and I want to create another in D:\dev\
. So I created one using File > Switch workspace > other > D:\dev\
. And in that workspace I imported some projects from the prevoius workspace. Yes I already see the projects in the dev workspace but when I open the other workspace (C:) I still see the imported projects and the folder (C:...\workspace) still contains the projects. What I want to do is to transfer the projects in a different workspace and in a different folder, which in my case D:\dev.
目前,我有C:\Users\krato\workspace\
我的默认工作区,我想在D:\dev\
. 所以我创建了一个使用File > Switch workspace > other > D:\dev\
. 在那个工作区中,我从 prevoius 工作区导入了一些项目。是的,我已经在开发工作区中看到了项目,但是当我打开另一个工作区 (C:) 时,我仍然看到导入的项目,文件夹 (C:...\workspace) 仍然包含这些项目。我想要做的是将项目转移到不同的工作区和不同的文件夹中,在我的情况下是 D:\dev。
I tried to refactor but it says that it overlaps with the workspace location.
我试图重构,但它说它与工作区位置重叠。
Please suggest the best way to do this.
请建议最好的方法来做到这一点。
I would also like to ask your recommendations whether I should have a same workspace and projects folder (like what I want to do) or different directories for my workspace and projects folder.
我还想问您的建议,我是否应该为我的工作区和项目文件夹使用相同的工作区和项目文件夹(就像我想要做的那样)或不同的目录。
回答by ferzle
If you didn't delete the projects from the first workspace, they will still be there. Did you copy the files from C: to D: or move them? If you copied them to D: and you don't want them on C:, delete them from C:. But make sure they really are on D: first.
如果您没有从第一个工作区中删除项目,它们仍将存在。您是否将文件从 C: 复制到 D: 或移动它们?如果您将它们复制到 D: 而您不想将它们放在 C: 上,请将它们从 C: 中删除。但首先要确保他们真的在 D: 上。
Or am I totally misinterpreting your question?
还是我完全误解了你的问题?
回答by stoyanr
Your project folders don't need to be where your Eclipse workspace is. In fact, I would recommend to keep them separate:
您的项目文件夹不需要位于 Eclipse 工作区所在的位置。事实上,我建议将它们分开:
- Your project folderscontain the project's code, together with Eclipse
.project
and.classpath
files. - Your workspaceon the other side contains Eclipse settings for working with your projects. It can contain multiple projects, and a project can be contained in multiple workspaces.
- 您的项目文件夹包含项目的代码以及 Eclipse
.project
和.classpath
文件。 - 您的工作空间的另一边包含与您的项目工作的Eclipse设置。它可以包含多个项目,一个项目可以包含在多个工作区中。
In your example, I would recommend to manually copy or move your code to D:\Dev
, create a new workspace in C:\Users\krato
, e.g. C:\Users\krato\workspace-dev
, and then import your projects there using Import existing projects.
在您的示例中,我建议您手动将代码复制或移动到,例如D:\Dev
在 中创建一个新工作区,然后使用Import existing projects在那里导入您的项目。C:\Users\krato
C:\Users\krato\workspace-dev
I would recommend moving rather than copying. If you really need a second copy of your project, consider using a version control system such as git and create a branch instead.
我建议移动而不是复制。如果您确实需要项目的第二个副本,请考虑使用版本控制系统(例如 git)并创建一个分支。
回答by Balder
To achieve what you want, you need to do the following:
要实现您想要的,您需要执行以下操作:
- Create a new Eclipse workspace(like you have done already)
- Import the projectsyou want to move using File/Import/General/Existing Projects and select the check box "copy projects into workspace"
- Delete the now copied projectsfrom the original workspace in Eclipse and select the check box "delete project contents on disk"
- 创建一个新的 Eclipse 工作区(就像您已经完成的那样)
- 导入项目你想使用文件/导入/一般/现有项目移动并选中该复选框“复制项目进入工作区”
- 从 Eclipse 中的原始工作区中删除现在复制的项目,并选中复选框“删除磁盘上的项目内容”
After that you will have completely moved the projects from one workspace to another, including the underlying folders.
之后,您将完全将项目从一个工作区移动到另一个工作区,包括底层文件夹。
I would also like to ask your recommendations whether I should have a same workspace and projects folder(like what I want to do) or different directories for my workspace and projects folder.
我还想问您的建议,我是否应该为我的工作区和项目文件夹使用相同的工作区和项目文件夹(就像我想要做的那样)或不同的目录。
It depends on your own preferences and, how the projects are going to be used. I prefer to have my main project folders separate from my workspaces, because some of them will reside on either SVN, GIT or also Dropbox. Especially library projects, that might be used by more than one other projects, are better kept in a separate workspace and/or folder. This allows one to keep the overview and one can simply include these library projects in other workspaces when needed.
这取决于您自己的喜好以及如何使用这些项目。我更喜欢将我的主要项目文件夹与我的工作区分开,因为其中一些将驻留在 SVN、GIT 或 Dropbox 上。尤其是可能被多个其他项目使用的库项目,最好保存在单独的工作区和/或文件夹中。这允许人们保留概览,并且可以在需要时简单地将这些库项目包含在其他工作区中。
回答by Eric
I believe I had a related problem, and conquered it.
我相信我有一个相关的问题,并克服了它。
I needed to move my entire workspace (containing my project directories) to a different drive, on Windows. If one wanted to move only some projects, and keep the old workspace as well, this could be modified simply by deleting projects as desired.
我需要在 Windows 上将我的整个工作区(包含我的项目目录)移动到不同的驱动器。如果只想移动一些项目,并保留旧的工作区,只需根据需要删除项目即可进行修改。
On http://www.eclipse.org/forums/index.php/t/248863/nwbeeson had written:
在http://www.eclipse.org/forums/index.php/t/248863/ 上,nwbeeson 写道:
Thank you. Here is exactly how to do this from a friend who is an Eclipse expert. 1. Open Eclipse and switch to Workspace1 using Switch To Workspace... 2. Check the projects in Workspace1 3. Switch to another workspace to make sure that Workspace1 is closed completely by Eclipse (Critical step!)4. Quit Eclipse 5. Copy Workspace1 and name the copy Workspace2 6. Copy Workspace2 to a USB flash drive 7. Copy Workspace2 from the USB flash drive onto the hard disk of a different computer 8. Open Eclipse on the new computer 9. Switch to Workspace2 using Switch To Workspace...
The projects open normally from Eclipse on any machine as though that workspace had been there all along. The critical step seems to be switching to another workspace before quitting Eclipse. If you skip that step the copied and transferred workspace does not open correctly.
谢谢你。以下是一位 Eclipse 专家朋友提供的具体方法。1. 打开 Eclipse 并使用 Switch To Workspace... 切换到 Workspace1 2. 检查 Workspace1 中的项目 3.切换到另一个工作区以确保 Workspace1 被 Eclipse 完全关闭(关键步骤!)4. 退出 Eclipse 5. 复制Workspace1 并将副本命名为 Workspace2 6. 将 Workspace2 复制到 USB 闪存驱动器 7. 将 Workspace2 从 USB 闪存驱动器复制到另一台计算机的硬盘上 8. 在新计算机上打开 Eclipse 9. 使用切换到工作区切换到 Workspace2。 ..
项目可以在任何机器上从 Eclipse 正常打开,就好像该工作区一直存在一样。关键步骤似乎是在退出 Eclipse 之前切换到另一个工作区。如果跳过该步骤,复制和传输的工作区将无法正确打开。
This worked perfectly. Without the critical step, Eclipse balked at the new workspace location. All sorts of references to old paths are used, and apparently updated only if the workspace was fully doubly hyperbolically closed prior to the copying of the workspace to a new location.
这工作得很好。如果没有关键步骤,Eclipse 就对新的工作区位置犹豫不决。使用了对旧路径的各种引用,并且显然只有在将工作空间复制到新位置之前工作空间完全双曲线闭合时才会更新。