9

我正在尝试重新熟悉 Eclipse 环境和 ant 集成。

问题是:如何将我的源目录 + build.xml 与工作区分开?

我拥有的是一个小型 java 项目及其 build.xml 文件,所有源代码都放在一个单独的项目文件夹下。然后我启动 Eclipse 并让它通过 New Project -> "Java Project from existing Ant Build File" 导入我的项目

一切都很顺利,直到我想使用 build.xml 从 Eclipse 内部构建项目。Ant 开始抱怨找不到源代码树。在我检查了工作区之后,我发现 Eclipse 已经将 build.xml 复制到了工作区中,所以很明显 ant 在那里找不到任何源。他们仍在我的项目总监手下,如果可能的话,我确实希望将他们留在那里。

那么最好的方法是什么让这个设置工作?一方面是工作区,另一方面是我的项目?

感谢!

编辑:我想要的甚至可能吗?

4

5 回答 5

11

Instead of using "Java Project from Existing Ant Buildfile", just create a simple "Java Project". In the wizard uncheck "use default location" and enter the path (or browse) to the top level directory of your existing project (i.e., where your build.xml is). True, eclipse will create .project and .classpath files in your project directory (if they do not already exist), but the project will remain outside the eclipse workspace.

Case in point, this setup has worked really well in a very particular situation on a standalone system where the source tree resides in a common location but each user has a workspace in a protected location. Using the method described above, each user of this system can create a project in their own eclipse workspace, execute ant targets and subsequently remove the project from their own workspace without affecting other users' workspaces.

于 2011-08-05T05:15:51.463 回答
2

使用链接怎么样?

于 2011-03-19T00:22:18.217 回答
1

I do this all the time in C++ projects (no Java, sorry, but I think the concept is portable).

I have my workspaces in ~/workspaces/{workspace_name}. I have a single shared project file in ~/{my_projects, and then the source trees (multiple versions) are in ~/proj1, ~/proj2, etc.

Within each ~/proj* directory, I put a symlink to ~/my_projects/.project and .cproject (required for C++, not used in Java). So each source tree is sharing the single project file. Then in each workspace (one for each source tree), I configure the workspace by importing the project link. For example, ~/workspaces/proj1 imports ~/proj1/.project, but ~/proj1/.project is actually a symlink to ~/my_projects/.project.

So this keeps the source separate from the workspaces. When building, there's no real configuration to do -- I just have Eclipse run make in the appropriate node of the tree -- we already have our own command-oriented build system (we're not using ant, but the same principle should apply).

I source-control the ~/my_projects folder in a private area of the SCM, so other team members don't see it or fiddle with it -- many of them don't use Eclipse at all.

于 2011-08-04T18:53:58.867 回答
0

实际上没有必要尝试避免使用同一组源文件的 Ant 和 Eclipse。事实上,他们使用同一套可能更好。

请记住,您实际上并没有混合任何东西。只有一组源文件,然后有两种不同的构建方式;蚂蚁和 Eclipse。这些构建器相互独立,因此与 Eclipse 耦合是没有问题的。您甚至可以愉快地将所有 eclipse 文件(.classpath、.project、.settings)提交到源代码管理,而不会影响使用不同 IDE 的任何开发人员。

于 2011-03-19T09:07:32.773 回答
0

我一直这样做(诚然使用 maven,而不是 ant),但同样的原则也适用。

如果您在 Eclipse 中有一个现有项目(在源代码树中有 .project),那么您可以 Import Project->Import Existing Project。当对话框出现时,您可以选择“将项目复制到工作区”。确保未选中此项,然后将它们导入。

您仍然将 .project 存储在原始源代码树中,但仅此而已。

所以现在我有

  1. code/xxx(包含 .java 文件,在 SVN 中)
  2. code/xxx-workspace(包含 eclipse 工作区)
于 2011-08-05T09:26:20.750 回答