Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How properly import maven projects to eclipse?

I have complex Maven project, which has a parent folder with parent pom.xml and some subfolders for subprojects, each with its own pom.xml.

When I checkout the parent folder from a SVN repository 'As maven projects', it correctly appears in the workspace each as separate project.

But now I made a checkout of the parent folder from other branch of project. I want to add this parent folder in the same manner to the current workspace. So I just select Import > Maven project, get the same dialogs as due checkout from svn, Eclipse finds all pom files with proper hierarchy and ask me give other name to parent project, cause the same name alredy exists (trunc version of project), I give it other name. But after import I get only parent folder as maven project in eclipse, all other subprojects are simple located under parent project as its subfolders.

So, how can I import such project properlty? I just want all subprojects created as maven projects too.

like image 850
sphinks Avatar asked Jun 07 '13 10:06

sphinks


1 Answers

Eclipse doesn't allow one project to be imported more than once, in your case from trunk and a branch. This article shows how you can bypass this limitation with a custom maven profile. Basically, the steps are:

  1. Add the following profile to your parent pom.xml

    <profiles>
      <!-- Specific profile used to append a string to project name -->
      <profile>
        <id>append-to-project-name</id>
        <activation>
          <property>
            <name>append.to.project.name</name>
          </property>
        </activation>
        <build>
           <plugins>
            <plugin>
              <artifactId>maven-eclipse-plugin</artifactId>
              <configuration>
                <projectNameTemplate>
                  [artifactId]-${append.to.project.name}
                </projectNameTemplate>
              </configuration>
            </plugin>
          </plugins>
        </build>
      </profile>
    </profiles>
    
  2. Before importing the project to Eclipse, let maven generate the project settings:

    mvn eclipse:eclipse -Dappend.to.project.name=[your-branch-name]

  3. Import the project to Eclipse as an existing project (not a maven project).

This should solve the naming issue.


As for import of child projects: I also have a parent maven project with child subprojects and use the m2e plugin for Ecplise. When I select Import > Existing Maven Project, I can check both the parent and children. After import, I have both the parent project and each child imported independently. Screens:

project importimported projects

So I hope this combined with the naming solution above should solve your problem.

like image 150
Mifeet Avatar answered Sep 20 '22 15:09

Mifeet