apache_maven

Maven projects are created using the New "Maven projects" from M2Eclipse, see here for more details
http://docs.codehaus.org/display/M2ECLIPSE/Creating+Maven+projects

Maven Modules are different beast, as they are suppose to have a parent in their hierarchy, if you use Maven
you are already understanding what the differences are.

You can get in troubles if you try to make a lot of maven projects in eclipse, although it may seems natural to do so. A lot
of people have gone that path, and this may work if you use the relativePath trick

  • parent (contains the super pom)
  • common-api, reference the parent using the <relativePath>../parent/pom.xml</relativePath>
  • common-core reference the parent using the <relativePath>../parent/pom.xml</relativePath>
  • common-spring reference the parent using the <relativePath>../parent/pom.xml</relativePath>
  • services-api   ...you get the idea
  • services-core
  • services-spring

Here is an example for common-spring:

<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.waltercedric</groupId>
<artifactId>common-spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
  <groupId>com.waltercedric</groupId>
    <artifactId>parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../parent/pom.xml</relativePath>
 </parent>
</project>

maven.all.projects. Do not make everything a Maven project!

With such a mapping you'll get in troubles! not all plug ins seems to support this kind of trick (relativePath)
In the maven reactor (maven-deploy, maven-release for example). It is a lot wiser to represent
your product or project also in eclipse in a tree manner. This will break the complexity, introduce
more flexibility, so why not just using maven modules??
Maven2 recommend to represent modules in a tree manner

|--- parent                                (packaging : pom)
|        | common                       (packaging : pom)
|                   |common-api       (packaging : any)
|                   |common-core     (packaging : any)
|                   |common-spring   (packaging : any)
|        | services                        (packaging : pom)
|                   |services-api        (packaging : any)
|                   |services-core      (packaging : any)
|                   |services-spring    (packaging : any)

To achieve that Goal, M2Eclipse use a trick and put all modules (common-xxx and services-xxx) in the
same maven project (parent) while displaying a workspace that look like "project flat"...

First create your product or project using a Maven Project

one.maven.project

focus on that project, and right click New... Others ... Maven Module

maven.module.helper new.maven.module

click Next, in the next page, choose a POM packaging, as this module will contains module
definition (aggregation of sub modules common-api, common-core, ...)
finish.module.creation

The results is what maven expect: a parent directory with a set of modules and pom's

result.maven.modules

The workspace fake the view and show maven modules as what I call "ghost projects"

Any changes in these "ghost projects" open in fact the Maven project (remember in fact
the code is there), so any change in common-api force you to sync and version the Maven project.

on the file system, it is even more visible, there is only one maven project (parent) and all its modules
are interlinked into it!

maven.interlinked.modules

you can create an unlimited number of modules interlinked in the maven project...
Some open source framework, prefers to name their first module level component-xxx, then all other modules-xxx

|--- myProduct                                      (packaging : pom)
|        | component-common                 (packaging : pom)
|                   |module-common-api       (packaging : any)
|                   |module-common-core     (packaging : any)
|                   |module-common-spring   (packaging : any)
|        | component-services                  (packaging : pom)
|                   |module-services-api        (packaging : any)
|                   |module-services-core      (packaging : any)
|                   |module-services-spring    (packaging : any)
comments powered by Disqus

You might like also

Fetching artifact programmatically through REST/API in Nexus 3.x
There is so many case where it is desirable to pull down artifact from Sonatype Nexus using REST API, unfortunately Nexus 3.x Rest API are still under development... Some use cases in Nexus 2.x: You have a script that uses REST call to pull down the LATEST maven artifacts every night from Nexus and deploys them. You make extensive use of the REST API in all your puppet modules You use the Atlassian Puppet module for Nexus for creating repository, …
725 Days ago
git-branch-renamer-maven-plugin
When working with many feature/release/bugix/hotfix branches, it is a bad idea to start changing the pom version as this will create merge conflicts using pull request. this plugin allow you to keep in ALL branches the same pom version for all your projects, for example MASTER-SNAPSHOT the version will be derived from branch name automagically :-) You may want to read more first these 2 short articles Update Maven pom version on GIT checkout in TeamCity maven-release-plugin with GIT git-branch-renamer-maven-plugin …
737 Days ago
Review: Getting Started with Apache Maven by Russell Gold
Some time ago I was asked if I would like to write a review about one of the new video courses from Packt Publishing. It was "Getting Started with Apache Maven" http://bit.ly/1fycmpP by Russell Gold and since I have been using Maven for some years now (since 2007) and did publish some articles myself, I thought it would be nice to help them promote Apache Maven. The course is organized in eight chapters, forty videos with a length between two …
1924 Days ago
Update Maven pom version on GIT checkout in TeamCity
Here is a solution to the following problems Deriving Maven artifact version from GIT branch, Update pom version on GIT checkout automatically, Add the ability to use Pull request with Apache Maven. You have a workflow requirement that require you to have the artifact version of a module externally defined from the current branch in GIT. For example You want to start working on a new feature branch “feature-memory-improvement”, so you branch from master a new branch named feature/feature-memory-improvement Having …
1929 Days ago
Easily Compress Web Application Resources with EhCache
Resources such as JavaScript and CSS files can be compressed before being sent to the browser, improving network efficiencies and application load time in certain case. If you are not using Apache with mod_deflate or nginx in front of your web application, you may need to implement resources compression yourself…. Wait! don’t start writing your own filter to compress files like CSS, html, txt, javascript it is way more difficult than you think to properly handle http response headers and …
2411 Days ago
Tomcat 7 and Apache Maven
Here is 3 different way to control the lifetime a local Tomcat 7 container using Apache Maven. A typical scenario would be to start a servlet container prior to running integration tests (Selenium, SAHI or using any other framework you can think of ) With the following examples, you will be able to start an instance of Tomcat 7 running your web application in the pre-integration-test phase and stop the instance in the post-integration-test phase. You can also decide to …
2411 Days ago
Apache Maven copy local file to a remote server server using SSH
I will show you in an Apache Maven configuration file how to copy files to server each time the package phase is executed. Solution with Ant SCP task This snippet of code is a ready to use code that make use of Apache Ant task scp, Just put this snippet of code in your Maven module where the assembly is executed or anywhere else to push all tar.gz files to a server just run a maven mvn package, you can …
2599 Days ago
Apache M2Eclipse: Get rid of Duplicate resources when opening resources and types
In this small post, I’ll show you how to remove duplicated resources in the Open Resource view of Eclipse Eclipse – M2Eclipse – Subversive …
2605 Days ago
Apache Maven 3 Cookbook
&160; First a big thanks to Packt Publishing for having sent me this book to review! I did enjoy going through this book, while I did not learn a lot of new stuff (I am using Apache Maven daily since 2006!), I found it to be concise and would recommend it anytime to any of my colleagues. But let’s go through my review of this cookbook of over 50 recipes towards optimal Java Software Engineering with Maven 3: Apache Maven
2747 Days ago
Apache Maven 3 Cookbook Review
Thanks to Packt Publishing for having sent me this book to review. I will publish a review in the next coming days Grasp the fundamentals and extend Apache Maven 3 to meet your needs Implement engineering practices in your application development process with Apache Maven Collaboration techniques for Agile teams with Apache Maven Use Apache Maven with Java, Enterprise Frameworks, and various other cutting-edge technologies Develop for Google Web Toolkit, Google App Engine, and Android Platforms using Apache Maven You …
2793 Days ago