Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Maven User
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<h1>Multi-modules projects</h1> <p>Imagine you are working on a project based upon a traditional 3 layered architecture, in which the layers are named presentation, business 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 : <img class="confluence-embedded-image image-center" src="/download/attachments/231080224/multi-projects.jpg?version=1&modificationDate=1369541955529" data-image-src="/download/attachments/231080224/multi-projects.jpg?version=1&modificationDate=1369541955529" data-linked-resource-id="231376346" data-linked-resource-type="attachment" data-linked-resource-default-alias="multi-projects.jpg" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="231080224" title="null > multi-projects.jpg"><br /> So to compile your presentation project, you would first need to compile the business project. But wait, the business project depends upon the integration project so it should be compiled first. Ok, let's 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): <br class="atl-forced-newline" /> <table class="wysiwyg-macro" data-macro-name="panel" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e3BhbmVsfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"> <p><em>/root_directory$/</em> <strong>cd integration</strong><br /> <em>/root_directory/integration$</em> <strong>mvn compile</strong><br /> <em>/root_directory/integration$</em> <strong>cd ..</strong><br /> <em>/root_directory$/</em> <strong>cd business</strong><br /> <em>/root_directory/business$</em> <strong>mvn compile</strong><br /> <em>/root_directory/</em><em>business</em><em>$</em> <strong>cd ..</strong><br /> <em>/root_directory$/</em> <strong>cd presentation</strong><br /> <em>/root_directory/presentation$</em> <strong>mvn compile</strong></p></td></tr></table><br class="atl-forced-newline" /></p> <p>Few! 8 lines just to compile! I thought Maven was simple. Of course, Maven offers a solution to this problem in the form of a multi-modules project.</p> <p>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 <strong>modules</strong>. When you run a command on the project, it will execute it on all of its children projects. Even better, Maven is able, through its <em>reactor component</em> (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:<br /> <img class="confluence-embedded-image image-center" src="/download/attachments/231080224/multi-modules+project.jpg?version=1&modificationDate=1369541955508" data-image-src="/download/attachments/231080224/multi-modules+project.jpg?version=1&modificationDate=1369541955508" data-linked-resource-id="231376344" data-linked-resource-type="attachment" data-linked-resource-default-alias="multi-modules project.jpg" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="231080224" title="null > multi-modules project.jpg"><br /> First, create a new directory named after your project, something like <strong>myproject</strong> (original isn't it?). Now let's write the pom file for your multi-modules project: <img class="confluence-embedded-image image-center" src="/download/attachments/231080224/multi-modules-pom.jpg?version=1&modificationDate=1369541955492" data-image-src="/download/attachments/231080224/multi-modules-pom.jpg?version=1&modificationDate=1369541955492" data-linked-resource-id="231376342" data-linked-resource-type="attachment" data-linked-resource-default-alias="multi-modules-pom.jpg" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="231080224" title="null > multi-modules-pom.jpg"><br /> As you can see, there is nothing very complex in this pom file. It is a normal parent project's pom file, which was introduced in the lesson [todo : link]. Only, this time there is something new: the modules section. The modules section allows you to declare the child modules of a parent project, hence the name multi-modules project. Modules are regular Maven projects which must be located under a subdirectory so the parent project can retrieve them easily. <br class="atl-forced-newline" /></p> <table class="wysiwyg-macro" data-macro-name="info" data-macro-parameters="title=Modules location" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2luZm86dGl0bGU9TW9kdWxlcyBsb2NhdGlvbn0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"> <p>Maven doesn't force you to place your modules at a specific location. You can put them wherever you want as long as they are under the parent project's directory and their paths are declared correctly in the modules section (for instance, modules/presentation). However, there is no point in not placing them directly under your parent project unless you really need to because of some external constraints.</p></td></tr></table> <p><br class="atl-forced-newline" /></p> <p>Next, create the following subdirectories and the pom.xml files that go with them <strong>[todo : explains the directory name restriction]</strong>: <img class="confluence-embedded-image image-center" src="/download/attachments/231080224/directory-layout.jpg?version=1&modificationDate=1369541955536" data-image-src="/download/attachments/231080224/directory-layout.jpg?version=1&modificationDate=1369541955536" data-linked-resource-id="231376347" data-linked-resource-type="attachment" data-linked-resource-default-alias="directory-layout.jpg" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="231080224" title="null > directory-layout.jpg"><br /> <br /> <br /> Now let's fill the presentation project's pom file: <img class="confluence-embedded-image image-center" src="/download/attachments/231080224/presentation-pom.jpg?version=1&modificationDate=1369541955475" data-image-src="/download/attachments/231080224/presentation-pom.jpg?version=1&modificationDate=1369541955475" data-linked-resource-id="231376340" data-linked-resource-type="attachment" data-linked-resource-default-alias="presentation-pom.jpg" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="231080224" title="null > presentation-pom.jpg"><br /> <br class="atl-forced-newline" /></p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced