Maven Tutorial 01
Maven Tutorial 01
org Maven
Intro to Maven
2.0
Javaero.org Maven
What is MAVEN?
-It defines a standard life cycle for building, testing and deploying
project artifacts.
Javaero.org Maven
Maven’s Origins
- Maven was borne of the practical desire to make several projects at
the Apache Software Foundation(ASF) work in the same, predictable
way.
- Before, every project at the ASF had a different approach to
compilation, distribution, and web site generation. Ex. Build process
for Tomcat was different from build process used by Struts. Turbine
developers used a different approach to site generation than the
developers of Jakarta Commons. Etc.
- This lack of common approach to building software meant that every
new project tended to copy and paste another project’s build system.
- The barrier to entry for a project with a difficult build system was
extremely high. Difficult to attract developer because it could take an
hour to configure everything in just the right way.
Javaero.org Maven
*This pom will allow you to compile, test and generate basic documentation.
Javaero.org Maven
Principles cont..
4. Coherent organization of dependencies.
<project>
:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
:
</project>
Dependencies… artifacts…repositories..
If the groupId is a fully qualified domain name such as z.y.x then you would end up with a
directory structure like the following.
Javaero.org Maven
2. New directory javaero has been created for the new project, and this
directory contains your pom.xml which looks like the ff:
Javaero.org Maven
6. Install the artifact(JAR file) you’ve generated into your local repository so
that it can be used by other projects. <your-home-
directory>/.m2/repository is the default location. Execute the ff:
c:\my-app> mvn install
Javaero.org Maven
Surefire plugin (which executes the test) looks for tests contained in files
with a particular naming convention. By default the ff tests are
included:
• **/*Test.java
• **/Test*.java
• **/*TestCase.java
for eclipse:
c:\my-app> mvn eclipse:eclipse
To have Maven filter resources from copying, simply set filtering to “true” for
the resource directory in your pom.xml:
Ex: <project>
:
</project>
Javaero.org Maven
Example:
1. Create src/main/resources/application.properties.
# application.properties
application.name= ${project.name}
application.version=${project.version}
2. Execute command: mvn process-resources
3. application.properties under target/classes directory, which
will go into a JAR looks like this:
# application.properties
application.name=Maven Quick Start Archetype
application.version= 1.0-SNAPSHOT
Javaero.org Maven
To reference a property file defined in external file:
Ex:
1. Create external property file src/main/filter/filter.properties
# filter.properties
my.filter.value=hello!
2. Add reference to this new file in pom.xml
Summary:
- Maven is a set of standards, a repository, a framework and is a
software.
- Maven is more than just downloading another JAR and a set of
scripts, it is the adoption of processes that allow you to take
your software to the next level.
Javaero.org Maven
References:
-http://maven.apache.org