Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 27 Next »

Multi-modules projects

Imagine you are working on a project based upon a traditional 3 layers architecture, in which the layers are named presentation, business logic and integration. Of course, you want each layer to be independant of all the other layers and so you want to produce one artifact for each one. Following the Maven norm, you will need to have one project for each layer. Hence, your setup should look like this :
So to compile your presentation project, you will first need to compile the business logic project. But wait, the business logic project depends upon the integration project so it should be compiled first. Ok, let us recapitulate, so to compile your presentation project you would need to type the following commands (we assume the projects have been put in a common root directory):

/root_directory$/ cd integration
/root_directory/integration$ mvn compile
/root_directory/integration$ cd ..
/root_directory$/ cd businesslogic
/root_directory/businesslogic$ mvn compile
/root_directory/businesslogic$ cd ..
/root_directory$/ cd presentation
/root_directory/presentation$ mvn compile

Few! 8 lines just to compile! I thought Maven was simple. Of course, Maven offers a solution to this problem in the form of multi-modules project.

A multi-modules project is a very particular type of project - it doesn't produce any artifact and is composed of several other projects known as modules. When you run a command on the project, it will executes it on all its children projects. Even better, Maven is able, throught its reactor component(don't worry about it for now), to discover the correct  execution order and to detect circular dependencies. So let's apply this solution to the last example. Your project should have the following structure at the end of this lesson :

Let's create your multi-modules project. First, create a new directory named after your project, something like multimoduleproject. Now let's write your multi-modules project's pom file :
[need some formatting] 

  • No labels