sphinks
sphinks

Reputation: 3128

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.

Upvotes: 14

Views: 33520

Answers (4)

Kris
Kris

Reputation: 14458

For importing complex (or indeed any) Maven projects from an SCM (be it SVN, Git or any other SCM) I use the following approach:

File->Import->Check out Maven Projects from SCM

This works best if no IDE specific files have been committed to the SCM. It will import all nested projects or you can choose which projects to import. It relies entirely on the Maven settings for determining the nature of the project being created so that, assuming the POM files are correct, you wind up with everything configured just right.

You may need to install add-ons so that m2eclipse can access the SCM of your choice.

Upvotes: 3

thSoft
thSoft

Reputation: 22660

Delete the projects that you had checked out as Maven projects, then check out the parent project simply (not as Maven project), then Import the child modules as Existing Maven projects. Make sure they are listed as child modules in the parent POM.

Upvotes: 0

Mifeet
Mifeet

Reputation: 13608

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 import imported projects

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

Upvotes: 9

roger_that
roger_that

Reputation: 9791

I guess there might be some workspace issue. You might have checked out the project in workspace itself(not sure so pardon for that). What you can do is, try checking out your project in some other drive and then import the parent project. You will again see all POMs aligned in hierarchical way and then i suppose, you won't be asked for entering name for parent project and this will do the trick.

Upvotes: 0

Related Questions