14

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.

2
  • I managed add new brach of such project only in new workspace, all other ways didn`t work for me.
    – sphinks
    Commented Jun 11, 2013 at 13:21
  • I stop trying to win in this battle, start use separate workspace for every branch.
    – sphinks
    Commented Jul 4, 2013 at 11:52

4 Answers 4

9

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.

3
  • About importing child projects. It perfectly work as you described on checkout as Maven project, but on importing existing project with the same dialog windows in eclipse it didn`t work properly.
    – sphinks
    Commented Jun 7, 2013 at 12:17
  • Thanks for this - follow on: does this copy the files into the workspace or leave them where they are pointed to in the import?
    – Mark
    Commented Oct 2, 2014 at 13:22
  • My guess is it doesn't copy files by default (it didn't in my case). Cannot verify, though, I have switched to IntelliJ Idea since :)
    – Mifeet
    Commented Oct 2, 2014 at 15:43
3

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.

2
  • I just wrote that I need to importe already existed project, not checkout it from svn. From svn different braches automaticly create some mess on hard drive in workspace folder (one branch in sub folder of other). SO I just checkout every branch in its own folder and import it in eclipse.
    – sphinks
    Commented Jun 7, 2013 at 12:15
  • This function can check out from branches just as easily. It is the only way I've been able to import nested Maven projects into Eclipse while maintaining ties to the SCM.
    – Kris
    Commented Jun 7, 2013 at 13:29
0

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.

5
  • No, Im entering the project name due to the project with the same name is already in workspace. So changing location of folder cant allow me to create one more project with the same name.
    – sphinks
    Commented Jun 7, 2013 at 12:12
  • Thats what i said, you are being prompted because project is already present in workspace. Try creating a new workspace and then import project which you have checked out(May be in some other directory)
    – roger_that
    Commented Jun 7, 2013 at 12:22
  • Do you mean checkout version from other branch to separate workspace?
    – sphinks
    Commented Jun 7, 2013 at 12:32
  • checkout to some other local directory. Create a new workspace. Import the newly checked out code to newly created workspace.
    – roger_that
    Commented Jun 7, 2013 at 12:33
  • Heh, its to simple to ask on stackoverflow, so you didnt read question carefully. I wrote in init question why I don`t want to do so. I was looking any way to get two bracnhes in same workspace.
    – sphinks
    Commented Jun 11, 2013 at 13:23
0

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.

3
  • It`s not good solution to import all child modules one by one. There are about 30 modules. Why should we do it manually if importing should do it in auto mode when import parent project/
    – sphinks
    Commented Jun 7, 2013 at 12:19
  • By importing the child modules I meant that in the Import existing Maven projects dialog, you browse for the parent project's directory and then select all POMs to import.
    – thSoft
    Commented Jun 7, 2013 at 14:53
  • Thats exatcly how Im doing. Select all pom to import scanning parent folder.
    – sphinks
    Commented Jun 11, 2013 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.