Getting started with maven 3 and multiple module project

The following tutorial will demonstrate how maven 3 can easy to create the multiple module support. I’ll explain step by step by create the project.

Download

Maven

The following article base on maven 3.0.3, you can download from maven website

PowerCmd
Optional download the PowerCmd tools. Because you can have multiple command dos in one screen. This is ease for development.

mvn archetype:generate

1) Open the command dos, type the above command. It will list down all the available supported project type. For our case, we need the 265 pom-root (Root project archetype for creating multi module projects). Input 265 and press enter.

2) Next, the command will prompt you to choose version: such as
1: 1.0
2: 1.0.1
3: 1.1
Choose a number: 3:

You can decide what version of your project.

3) Enter the following information,

You can leave the version and package as default if you providing the groupId information.

4) From the step 3, you had create the parent project with supply the argument. Now you can create the submodule with reuse the parameter as well. For instance we are going to create 2 submodule: myexhibition-persistance and myexhibition-web.

5) Web module, to create a web module with following command under myexhibition main project.
mvn archetype:generate -DgroupId=com.myexhibition -DartifactId=myexhibition-web

and choose 110 maven-archetype-webapp (An archetype which contains a sample Maven Webapp project.)

6) DB module, to create a persistent module with following command under myexhibition main project.
mvn archetype:generate -DgroupId=com.myexhibition -DartifactId=myexhibition-persistent

Modules dependencies

During the compile times, you may encounter your own library dependencies issues. This can be solved in easy with the following sequencies.

1) Let’s say myexhibition-web depends on myexhibition-persistent.
2) Go the the project myexhibition-persistent, build your project with mvn package
3) Manual install this project into your local repository. PS:( Do not use mvn install )
4) Example:

  1.  
  2. mvn install:install-file
  3.    -DgroupId=myexhibition
  4.    -DartifactId=myexhibition-persistent
  5.    -Dversion=1.0 -Dpackaging=jar
  6.    -Dfile=C:\workspace\myexhibition\myexhibition-persistent\
  7.           target\myexhibition-persistent.jar

5) Next, go back to your parent project run mvn clean eclipse:eclipse
6) Go to your myexhibition-web check the libraries from properties.

You can leave a response, or trackback from your own site.

Leave a Reply

Security Code: