Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Design

Maven: Building Complex Systems


What Is Maven?

Maven is all about large-scale Java-based software projects. It advocates a standard lifecycle, standard directory layout, various best practices, extensive reports, documentation facilities, and it is totally extensible through plug-ins to boot. You may, of course, customize the default directory layout and lifecycle if you have special needs. The maven core is an engine scans your project directory tree for pom.xml files and executes the build lifecycle based on the information in the pom.xml.

Maven advocates using a standard directory layout for your source files, resources, and intermediate artifacts. The benefit of this convention is that developers feel right at home when they browse a new project and don't have to specify a lot of information because Maven assumes the files are organized according to the recommend directory layout. You may override everything of course, but usually it's counter productive. Table 1 contains the standard directory layout for a single project.

Files Explanation
src/main/java Application/Library sources
src/main/resources Application/Library resources
src/main/filters Resource filter files
src/main/assembly Assembly descriptors
src/main/config Configuration files
src/test/java Test sources
src/test/resources Test resources
src/test/filters Test resource filter files
src/site Site
LICENSE.txt Project's license
README.txt Project's readme
target

Table 1: Directory layout for a single project.

Maven promotes a standard build lifecycle where various plugins may hook into in order to customize or enhance it. The standard lifecycle phases are described in Table 2. The <packaging> element in the pom.xml file determines the build lifecycle for a specific project. When building a project using a command such as "mvn install" Maven will go through all the lifecycle phases up to (and including) the specified phase. The standard lifecycle makes the whole process much simpler because you don't have to graft it into the build system yourself. The good people of Maven put all the lifecycle phases that yo are likely to need even in a complex project (source-code generation, for instance) and if you happen to be an unlikely person then you are free to customize the lifecycle and hook into it using custom plugins.

Files Explanation
validate validate the project is correct and all necessary information is available
generate-sources generate any source code for inclusion in compilation.
process-sources process the source code, for example to filter any values.
generate-resources generate resources for inclusion in the package.
process-resources copy and process the resources into the destination directory, ready for packaging.
compile compile the source code of the project.
process-classes post-process the generated files from compilation, for example to do bytecode enhancement on Java classes.
generate-test-sources generate any test source code for inclusion in compilation.
process-test-sources process the test source code, for example to filter any values.
generate-test-resources create resources for testing.
process-test-resources copy and process the resources into the test destination directory.
test-compile compile the test source code into the test destination directory.
test run tests using a suitable unit testing framework. should not require the code be packaged or deployed.
package take the compiled code and package it in its distributable format, such as a JAR.
integration-test process and deploy the package if necessary into an environment where integration tests can be run.
verify run any checks to verify the package is valid and meets quality criteria.
install install the package into the local repository, for use as a dependency in other projects locally.
deploy done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects..

Table 2: Standard lifecycle phases.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.