如何将 Eclipse 工作区和项目从 Windows 转移到 Linux 和 Mac

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

How to transfer Eclipse workspace and project from Windows to Linux and Mac

windowslinuxeclipseworkspace

提问by

We have a a product developed on Windows for years. The product is composed of one Eclipse workspace and about 20 projects. On Windows, we ask every developer check out projects into d:\dev\product folder, and copy a unified Workspace to d:\dev\prod_workspace. This way, whenever a new machine is set, we simply copy files to the same folder, and we can start working immediately.

我们在 Windows 上开发了多年的产品。该产品由一个 Eclipse 工作区和大约 20 个项目组成。在 Windows 上,我们要求每个开发人员将项目签出到 d:\dev\product 文件夹中,并将统一的 Workspace 复制到 d:\dev\prod_workspace。这样,每当设置新机器时,我们只需将文件复制到同一个文件夹,我们就可以立即开始工作。

Now we need to move our development environment to Linux and Mac. But there's no D:\ on Unix. And home folder for Linux is mostly like /home/username and /Users/username for Mac. We found Eclipse keeps absolute path in workspace when referring to projects, so simply copy workspace over does not work anymore. Even when we manually create/configure workspace on a Linux machine, it still cannot be copied over to another user, because the absolute path is changed.

现在我们需要将我们的开发环境迁移到 Linux 和 Mac。但是 Unix 上没有 D:\。Linux 的主文件夹大多类似于 Mac 的 /home/username 和 /Users/username。我们发现 Eclipse 在引用项目时会在工作区中保留绝对路径,因此简单地将工作区复制过来不再起作用。即使我们在 Linux 机器上手动创建/配置工作区,它仍然无法复制到另一个用户,因为绝对路径已更改。

I guess our goal is to allow easy setup of development environment. Do you have any suggestion to move eclipse workspace around?

我想我们的目标是允许轻松设置开发环境。你有什么建议来移动 eclipse 工作区吗?

回答by Uri

I develop an Eclipse based product for Mac and WIndows (haven't tried Linux).

我为 Mac 和 WINdows 开发了一个基于 Eclipse 的产品(还没有尝试过 Linux)。

The solution I found to work best is to actually go and manually check out the projects in the workspace on each machine directly from source control. While the project structure does convert between platforms, any attaches, such as version-control stuff does not. I am not sure why, but I guess each thing has its kinks. You may be able to able to hasten things a little by creating a project working set (or whatever it's called, I think it's a PSF file) for a platform, and then reuse it on all platforms.

我发现最有效的解决方案是直接从源代码管理中手动检查每台机器上工作区中的项目。虽然项目结构确实在平台之间转换,但任何附件,例如版本控制的东西都不会。我不知道为什么,但我想每件事都有它的缺点。您可以通过为一个平台创建一个项目工作集(或者不管它叫什么,我认为它是一个 PSF 文件)来加快速度,然后在所有平台上重用它。

Another problem is that Eclipse versions are not 100% compatible. One of the problems I have is with manifest files for plugins, which have different semantics (e.g., what to do with exported packages that don't actually exist) in each platform, causing a headache.

另一个问题是 Eclipse 版本不是 100% 兼容的。我遇到的问题之一是插件的清单文件,它们在每个平台上都有不同的语义(例如,如何处理实际上不存在的导出包),这引起了头痛。

Finally, be away that Java on Mac and PC are not identical. In fact, Eclipse has two versions for the Mac. I usually end up running and compiling on Java 5 on the mac, which does have some incompatibilities with Java 6.

最后,请注意 Mac 和 PC 上的 Java 并不相同。事实上,Eclipse 有两个适用于 Mac 的版本。我通常最终在 mac 上运行和编译 Java 5,这与 Java 6 确实存在一些不兼容。

回答by stack programmer

I have ported my eclipse project from windows xp to RHEL(never tried Mac)

我已将我的 eclipse 项目从 windows xp 移植到 RHEL(从未尝试过 Mac)

Your task can be accomplished in the following steps :-

您的任务可以通过以下步骤完成:-

  1. Use workspace variables in your project code rather than absolute path.
  2. Shift your workspace to some location in linux as /Workspace or if you want to keep it user specific make the workspace folder as /home/user_name/Workspace.
  3. There is an option to change all the \ of windows to / in linux. The option can be found under the file menu in eclipse.
  4. Change the settings of where to find classpath directories, the options can be found by just right clicking on the project menu in the project viewer panel.
  5. There is an option to build the project clean from scratch. You just have to click on the option and eclipse would re-compile the project.
  1. 在项目代码中使用工作区变量而不是绝对路径。
  2. 将您的工作区作为 /Workspace 移动到 linux 中的某个位置,或者如果您想保持它特定于用户,请将工作区文件夹设为 /home/user_name/Workspace。
  3. 有一个选项可以将 Windows 的所有 \ 更改为 / 在 linux 中。该选项可以在 eclipse 的文件菜单下找到。
  4. 更改在何处查找类路径目录的设置,只需右键单击项目查看器面板中的项目菜单即可找到这些选项。
  5. 有一个选项可以从头开始构建干净的项目。您只需单击该选项,eclipse 就会重新编译该项目。

Once all this is done, and all your database connections have been successfully ported to linux, you would have a working project running in linux as well.

一旦所有这些都完成了,并且您的所有数据库连接都已成功移植到 linux,您也将有一个在 linux 中运行的工作项目。

回答by Thorbj?rn Ravn Andersen

If you check out the projects from a source repository, then consider using Team -> ProjectSets to handle these.

如果您从源存储库中检出项目,请考虑使用 Team -> ProjectSets 来处理这些项目。

Preferences can be saved in a file and loaded.

首选项可以保存在文件中并加载。

We tried classpath variables and loathed them. Now we just have everything in single projects in the source repository.

我们尝试了类路径变量并讨厌它们。现在我们只在源存储库中的单个项目中拥有所有内容。

回答by charlob

I'll share my own solution:

我将分享我自己的解决方案:

Zip the workspace. Just zip the entire file and then transfer it over. Then, all you need to do is delete the default drive reference:D:\...or whatever ends up appearing in the beginning of your file name. Then all you need to do is drag it over to the new empty workspace on your newly downloaded Eclipse.

压缩工作区。只需压缩整个文件,然后将其传输过来。然后,您需要做的就是删除默认的驱动器引用:D:\...或最终出现在文件名开头的任何内容。然后您需要做的就是将它拖到新下载的 Eclipse 上的新空工作区。

回答by Chip McCormick

Use the Workspace Preference Transferrer plugin

使用Workspace Preference Transferrer 插件

This allows you to transfer the workspace settings from a given workspace to another via new options in the 'switch workspaces' dialog.

这允许您通过“切换工作区”对话框中的新选项将工作区设置从给定的工作区转移到另一个工作区。

回答by Eddie

I can think of two ways to do this:

我可以想到两种方法来做到这一点:

  1. Use workspace variables in Eclipse to point to the exact location where the workspace sits, if you need that. Then the developer can put everything in the workspace on Windows, Unix, whatever, then define the variable and you're done, or
  2. If compilation is always done from within Eclipse, meaning you don't truly need any absolute paths anywhere, then change the projects to all use relative paths and check the Eclipse classpaths, etc, into source control. Thus, when a developer checks out everything in Eclipse, the classpath and .projectfile will be at the root level in the project and all paths will be pre-defined.
  1. 如果需要,在 Eclipse 中使用工作区变量指向工作区所在的确切位置。然后开发人员可以把所有东西放在 Windows、Unix 上的工作区中,然后定义变量,你就完成了,或者
  2. 如果编译总是在 Eclipse 中完成,这意味着您在任何地方都不需要任何绝对路径,然后将项目更改为全部使用相对路径并将 Eclipse 类路径等检查到源代码控制中。因此,当开发人员检查 Eclipse 中的所有内容时,类路径和.project文件将位于项目的根级别,并且所有路径都将被预定义。

For option #2, you may need to have multiple .projector .classpathfiles, and have the developer copy the appropriate one into location. That is, copy .classpath.wininto .classpathfor Eclipse's use.

对于选项#2,您可能需要有多个.project或多个.classpath文件,并让开发人员将适当的一个复制到某个位置。也就是说,copy .classpath.wininto.classpath供 Eclipse 使用。