简体   繁体   English

在Eclipse中处理Maven多模块项目

[英]Working on maven multi-module project in Eclipse

I am creating my first hierarchical multi-module project in Eclipse: 我正在Eclipse中创建我的第一个分层多模块项目:

 /project
    pom.xml
      (...)
      <groupId>a.b.c</groupId>
      <artifactId>myProject</artifactId>
      <version>1.0-SNAPSHOT</version>
      <packaging>pom</packaging>
      <modules>
        <module>x</module>
        <module>y</module>
      </modules>
    /x
      pom.xml
        (...)
        <parent>
          <artifactId>myProject</artifactId>
          <groupId>a.b.c</groupId>
          <version>1.0-SNAPSHOT</version>
        </parent>    
      /src
      .project
    /y
      pom.xml
        (...)
        <parent>
          <artifactId>myProject</artifactId>
          <groupId>a.b.c</groupId>
          <version>1.0-SNAPSHOT</version>
        </parent>    
      /src
      .project

Ideally, I would like to see in my Eclipse workspace three folders: 理想情况下,我希望在Eclipse工作区中看到三个文件夹:

  /project
    pom.xml
  /x
    pom.xml
    src
    .project
  /y
    pom.xml
    src
    .project
  • x and y would find the parent pom.xml in the project folder. x和y将在项目文件夹中找到父pom.xml。 I would be able to work on them independently as maven projects. 我将能够作为Maven项目独立地处理它们。

  • project would only contain the parent pom.xml 项目将仅包含父pom.xml

At least that's my intuition on how it would be practical to work on this project. 至少这是我对进行此项目的实践的直觉。

I committed my code in SVN and I can get close to that structure by doing an SVN checkout using option "Find projects in the children of the selected resource" (available as long as there is not a .project in the parent project folder). 我在SVN中提交了代码,可以通过使用选项“在选定资源的子项中查找项目”(只要在父项目文件夹中没有.project的情况下)进行SVN签出,可以接近该结构。 This creates projects x and y in my workspace, but I get compilation errors because of the missing parent pom.xml. 这将在我的工作空间中创建项目x和y,但是由于缺少父pom.xml,我得到了编译错误。 I can get rid of these errors by putting the parent pom.xml in the workspace on its own, but that doesn't seem a clean solution. 我可以通过将父pom.xml单独放置在工作区中来摆脱这些错误,但这似乎不是一个干净的解决方案。

I suppose that one solution to my problem would be to flatten my structure some and create a 'parent' folder at the same level as x and y and my parent pom.xml and a .project file in there, but it seems odd to have to put the parent at the same level as the child just for the sake of making Eclipse happy. 我想解决这个问题的一种方法是将我的结构弄平,并在与x和y相同的级别上创建一个“父”文件夹,并在其中创建父级pom.xml和一个.project文件,但是这样做似乎很奇怪。为了使Eclipse高兴,使父级与子级处于同一级别。 The closest to an answer that I found online is http://warpedjavaguy.wordpress.com/2011/08/08/how-i-defeated-the-maven-release-plugin-in-a-flat-structured-multi-module-project/ , which seems to approach the problem in a similar way. 我在网上找到的最接近答案的是http://warpedjavaguy.wordpress.com/2011/08/08/how-i-defeated-the-maven-release-plugin-in-a-flat-structured-multi- module-project / ,似乎以类似的方式解决了这个问题。

Is there a better approach that I am missing? 是否有我所缺少的更好的方法?

PS: I have m2e. PS:我有m2e。

I think I am answering my own question here. 我想我在这里回答自己的问题。

  • I checked out the project outside of Eclipse. 我在Eclipse外部签出了该项目。
  • Then I Imported as a maven project 然后我导入为Maven项目

I got exactly the view I expected: ie 4 folders in my workspace(one for the parent and 3 for each of the children). 我得到的正是我所期望的视图:即,我的工作区中有4个文件夹(一个用于父级,每个子级3个)。 Somehow, I recall there was an option to do exactly this in one step (ie checkout and import) with my previous version of Eclipse. 我以某种方式回想起,有一个选项可以使用我以前的Eclipse一步来完成此操作(即签出和导入)。 It was called "Check out as maven project" and it seems to have disappeared with Juno. 它被称为“以Maven项目签出”,似乎与Juno一起消失了。 Or perhaps I am missing the correct plugin (I have m2e installed as well as Subversive; it could be that another svn plugin does that instead of subversive). 或者,也许我缺少正确的插件(我安装了m2e以及Subversive;这可能是另一个svn插件代替了Subvive所做的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM