| Apache Maven | |
|---|---|
| Developer | Apache Software Foundation |
| Latest release | 2.0.8 / November 27, 2007 |
| OS | Cross-platform |
| Genre | Build Tool |
| License | Apache 2.0 licence |
| Website | maven.apache.org |
- For other uses of the word Maven see: Maven (disambiguation)
Maven is a software tool for Java programming language project management and automation created by Jason van Zyl in 2002. It is similar in functionality to the Apache Ant tool (and to a lesser extent, PHP's PEAR and Perl's CPAN), but has a simpler build configuration model, based on an XML format. Maven is hosted by the Apache Software Foundation, where it was formerly part of the Jakarta Project. Maven uses a construct known as a Project Object Model (POM) to describe the software project being built, its dependencies on other external modules and components, and the build order. It comes with pre-defined targets for performing certain well defined tasks such as compilation of code and its packaging. A key feature of Maven is that it is network-ready. The core engine can dynamically download plug-ins from a repository, the same repository that provides access to many versions of different Open Source Java projects, from Apache and other organisations and developers. This repository and its reorganized successor, the Maven 2 repository, strives to be the de facto distribution mechanism for Java applications, but its adoption has been slow. Maven provides built in support not just for retrieving files from this repository, but to upload artifacts at the end of the build. A local cache of downloaded artifacts acts as the primary means of synchronizing the output of projects on a local system.
Contents |
Theory
Reuse
The whole idea of Maven is reuse - reuse of build logic. The general idea is that we build our projects the same way all the time, so why shouldn't we reuse the way we build them? The main idea is not to reuse the code or functionality (like Apache Ant), but to simply change the configuration of already written code. That's the main difference between Apache Ant and Apache Maven: one is a library of good and useful utilities and functions, while the other is a configurable and highly pluggable framework. Maven is a highly configurable framework, but the main idea is to change as little as possible, to stay with the defaults, so everything will work out of the box.
Life cycle
The parts of the main Maven project life cycle are: compile, test, package, install, deploy The idea is that, for any goal, all previous goals have already been successfully accomplished. For example, when you run mvn install Maven will check if mvn package has successfully been run (the jar exists in target/), in which case it will not be run again. Also, there are some goals that are outside the life cycle that can be called, but Maven assumes that these goals are not part of the default life-cycle (don't have to be always performed). These goals are: assembly:assembly, site, site-deploy, etc. But these goals can be added to the default life cycle through the project's POM.
The POM
Assembly descriptor
Commands
Project creation
Component creation
In order to create a maven project all one has to do is mvn archetype:create -DgroupId="com.your.company" -DartifactId="your-project" -Dversion="0.0.1"
Module (Multi module project)
You do the same thing as with the component, but you do it in the directory of the father POM and you change the father's POM <packaging>jar</packaging> to <packaging>pom</packaging>
Compilation
In order to compile the source files (default in src/main/java/*) mvn compile The files are compiled and put to target/classes.
Testing
Running JUnit 3.8 test
In order to run unit tests (default in src/test/java/*). mvn test The unit tests are compiled , put to target/test-classes, the unit tests are run and the test reports put in target/surefire-reports/ .
Running JUnit 4 tests
For now you must add:
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.3</version>
</plugin>
</plugins>
</build>
Jar creation
Creates a jar (default name ${artifactId}-${version}.jar) mvn package and puts it in target/
Local installation
Puts the created jar in local ~/.m2/repository/${groupId}/${artifactId}/${version} so different projects on the same computer can use it. mvn install
Creating an assembly
Assembly is a package given to a customer/QC engineer, configured through the assembly descriptor Creates an assembly and puts it in target mvn assembly:assembly
Project Information
In order to check exactly what definitions you use: mvn projecthelp:effective-pom mvn projecthelp:effective-settings
Maven Plugins Configuration
javadoc
Adding overview file
Add this to the POM:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<overview>${basedir}/src/main/javadoc/overview.html</overview>
</configuration>
</plugin>
</plugins>
</reporting>
Adding images
In order to add images , for example in your overview file , you must put them in ${basedir}/src/main/javadoc/doc-files and put them in the HTML using relative path: <img src=doc-files/my-image.jpg />
Java 5 compliance
In order to have your project working on Java 5 - source and binary compliance add the following to your POM:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
See also
- Apache Continuum, a continuous integration server which integrates tightly with Maven
External links
- Maven 1.x Home Page
- Maven 2 Home Page
- Maven plugins
- Maven 2 codehaus tutorial
- Maven 2 tutorial on java.net
- Free Maven2 Book
- Free Maven2 Book
- Maven Training from Sonatype
|
|
|
|---|---|
| Top level projects | ActiveMQ · Ant · Apache HTTP Server · APR · Beehive · Camel · Cayenne · Cocoon · Commons · Directory · Excalibur · Felix · Forrest · Geronimo · Gump · Harmony · HiveMind · iBATIS · Jackrabbit · James · Lenya · Maven · mod_perl · MyFaces · OFBiz · OpenEJB · OpenJPA · POI · Roller · Shale · SpamAssassin · Struts · Tapestry · Tomcat · Velocity · WebWork 2 · Wicket · XMLBeans |
| Other projects | Jakarta Project · Apache Lucene · Apache XML · Apache Incubator |
| Sub-projects | BCEL · BSF · Cactus · JMeter · Slide · Xerces · Batik · FOP · Log4j · XAP · River · ServiceMix · Log4Net · Abdera · Ivy · CXF · Hadoop |
| License: Apache License · Website: http://apache.org/ | |


