= Maven =
Maven uses a Project object model to manage a software project. It manages
* reporting
* documentation
* building
Maven can
* build multiple projects together
* can manage:
* builds
* documentation
* reporting
* dependencies
* SCMs
* Releases
* distribution
* mailing lists
*All maven project structure is in an xml file called pom.xml*
For a quickstart, go to [[#Creating a project]]
Maven uses sensible defaults, requiring minimal configuration on the part of
the developer. Some defaults are below
| Item | Default |
| source | /src/main/java |
| resources | /src/main/resources |
| tests | /src/test |
| compiled byte code (.o) | /target |
| jar | /target/classes |
== pom.xml ==
This is the configuration file for maven, it lives in the base directory of the
project as pom.xml. There is a single POM file for each project
A POM requires a
* groupId
* artifactId
* version
With this notation, all projects are notated as
`groupId:artifactId:version`
Example POM
{{{
4.0.0
com.companyname.project-group
project
1.0
}}}
=== Super POM ===
All POM files inheret from the Super POM, this file is the default
configuration of all projects.
To view the current configuration, run `mvn help:effective-pom`
== Creating a project ==
Maven uses archetype plugins to create projects. These are essentially
templates.
To create a simple java application, run the following command
{{{
mvn archetype:generate \
-DgroudId = com.company.subcompany \
-DartifactId = ProjectName \
-DarchetypeArtifactId = maven-archetype-quickstart \
-DinteractiveMode = false
}}}
This command specifies,
* the group
* the project
* the type of template to use (quickstarrt)
* to not be interactive
== Build lifecycle ==
The general lifecycle, or sequence of phases that maven takes are as follows
| phase | handles |
| prepare-resources | resource copying |
| validate | validate if all resources present |
| compile | compilation |
| test | testing with a framework |
| package | packaging (into jar) |
| install | installing in local repo |
| deploy | copy final package to remote repo |
== Plugins ==
All functionality in maven is in frameworks, making it modular. Maven built in
plugins due most basic operations including
* creating jar files
* create war file
* compile code files
* unit testing
* create documenation
* create reports
Some built in plugins include,
| name | job |
| clean | clean up target |
| compiler | compile java source |
| surefire | run JUnit tests |
| jar | build JAR file |
| war | build WAR file |
| javadoc | create javadoc |
| antrun | run ant tasks from any phase |
=== Site ===
Site is a plugin to create documentation to create reports, deploy site, etc
== Build profiles ==
Build profiles can be specified with the `-P` flag when `mvn` is called.
Profiles can be configured with the `` tag. A more thurough example
is below
{{{
test
org.apache.maven.plugins
maven-antrun-plugin
1.1
test
run
Using env.test.properties
}}}
Note that at the `` tag, you can specify what happens when that profile
is selected. In this instance, it copies a properties files to the correct
directory. The name of the profile that is passed on the command line is
configured with the `` tag.
Activation elements can be added to build profiles with the `` tag.
This tag can take arguments or paramaters to check against in the enviroment it
is running, to automatically determine what profile to activate. Below are some
examples
Via enviroment var
{{{
test
env
test
}}}
Via OS (the example tirrgers on Windows XP)
{{{
test
Windows XP
Windows
x86
5.1.2600
}}}
Via present/missing files (the example checks the path in the `` tag)
{{{
test
target/generated-sources/axistools/wsdl2java/
com/companyname/group
}}}
== Repositories ==
A repository in maven terminology is a directory where project jars, library
jars, plugins, etc are stored and used by maven. There are three types
* local
* central
* remote
=== Local ===
A local maven repo is created first time you run maven on your machine. When
`mvn build` is run for the first time, it downloads all dependency jars
=== Central ===
The central repo is one provided by the maven community, it contains common
libraries. When a dependency is not found in the local repo, it automatically
searches the central repo.
In general key concepts,
* managed by maven community
* not required to be configured
* must have internet
=== Remote ===
A remote repo is only searched when specified via the `` tag in
the pom.xml file. It specifies a url for maven to search on. These repos are
usually internal repos maintained by companies internally.