Using Eclipse for multi-module Maven2 projects (part 3)

December 23, 2008 at 4:32 pm 3 comments

In the last post in this series we used the m2eclipse plugin to create a Maven webapplication in Eclipse. In this post we’ll create a multi-module Maven application.

This will be a quite lengthy post, with lots of screenshots, so we’ll delve right into the creation of this multi-module beast!

First create a new Maven Project:

New Maven Project

Because this project will be the parent project, you should skip the archetype selection:

Skip the archetype selection for the parent project

In the following screen you should enter some details of the project. As a groupId choose your package path (this is just a convention, not obligatory). Set the artifactId and name to your project name, e.g. SearchApp. Packaging should be pom, as we won’t create any code in this parent project, just a pom file.  Click finish to create the parent project.

Now we’ll add some modules to this parent project. Create a new project, but this time choose Maven Module instead of Maven Project. Select a name for the module, e.g. SearchCore. Tick the correct archetype (e.g. webapp if you want this module to create a war file) and follow the next steps. If all went well your project structure should look like below (my parent has another name because it’s an old screenshot):

Parent project with one child module

Now add some folders (src\main\java, src\test\java etc) and update the configuration. 

Update configuration

 

We will now share the project code using SVN as we did before. Right click on the parent project and select Team>Share Project. The project will be checked into SVN. After a refresh, you can see it in the SVN repo browser:

Project is checked into SVN

As in previous posts, add some files to the svn ignore list (the .settings, the .project and .classpath files). Do an svn-commit of the main project (and therefore also of the subprojects). I was not able to add files of the subproject to the svn ignore list, so you’ll have to deselect these files manually. 

Commit project to svn

All files are added to svn. The next step is weird but saved me from some quirks so just do it :-). We will delete the project and check it out from svn again. Delete the main project (tick “delete contents from disk”!) in Eclipse. Then choose new project ->  Maven -> Checkout Maven Projects from SCM and choose your parent project. If all goes well you should have your parent and child project back in Eclipse. We are sure everything is correct on the svn repo now. You can add the subprojects target folder to svn:ignore now.

Now we can add some sourcecode, finally!  You know how to do this, so I won’t go deeper into it.

If your java version keeps popping back to 1.4 after e.g. an update of project configuration you should add a build plugin to the pom that tells Maven to compile against java 1.6:

 <build>
   <plugins>
    <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.0.2</version>
    <configuration>
    <source>1.6</source>
      <target>1.6</target>
    </configuration>
    </plugin>
</plugins>
</build>

Commit the sourcecode (svn commit and tick “show unversioned files” because we want to add the new ones), and congratulate yourself because you have succesfully created a multi module maven project, and used it with subversion!

This post was rather long (because of all the screenshots). This concludes the three part series of using Maven and Eclipse. In a follow-up I will write about the use of Selenium and Hudson to create a fully automatic build and test environment, so stay tuned!

[part 1]
[part 2]

Advertisements

Entry filed under: java, Uncategorized. Tags: , , , , , .

Using Eclipse for multi-module Maven2 projects (part 2) Two of the best free applications out there

3 Comments Add your own

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Feeds

Articles to be written…

Twitter – kr3l

my del.icio.us

RSS Google Reader Shared Stuff

  • An error has occurred; the feed is probably down. Try again later.

RSS Listening to..

  • An error has occurred; the feed is probably down. Try again later.

%d bloggers like this: