-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Mastering Apache Maven 3
By :

Convention over configuration is one of the main design philosophies behind Apache Maven. Let's go through a few examples.
A complete Maven project can be created using the following code snippet in pom.xml
file:
<project> <modelVersion>4.0.0</modelVersion> <groupId>com.packt</groupId> <artifactId>sample-one</artifactId> <version>1.0.0</version> </project>
Downloading the example code
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
The Maven POM file starts with the <project>
element. Always define the <project/>
element with the corresponding schema. Some tools can't validate the file without it.
<project xmlns=http://maven.apache.org/POM/4.0.0xmlns:xsi=………xsi:schemaLocation="…">
Copy the previous configuration element and create a pom.xml
file out of it. Then, place it in a directory called chapter-01
and create the following child directories under it:
chapter-01/src/main/java
chapter-01/src/test/java
Now, you can place your Java code under chapter-01/src/main/java
and test cases under chapter-01/src/test/java
. Use the following command to run the Maven build:
$ mvn clean install
This little configuration is tied up with many conventions:
{base-dir}/src/main/java
{base-dir}/src/test/java
{base-dir}/target/classes
{base-dir}/target
If someone needs to override the default, conventional behavior of Maven, that is possible too. The following sample pom.xml
file shows how to override some of the preceding default values:
<project> <modelVersion>4.0.0</modelVersion> <groupId>com.packt</groupId> <artifactId>sample-one</artifactId> <version>1.0.0</version> <packaging>jar</packaging> <build> <sourceDirectory>${basedir}/src/main/java</sourceDirectory> <testSourceDirectory>${basedir}/src/test/java </testSourceDirectory> <outputDirectory>${basedir}/target/classes </outputDirectory> </build> </project>
Change the font size
Change margin width
Change background colour