MAVEN

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

PAJ

What is Maven?

Managing Projects in Maven

Archetypes

Dependencies

Lifecycles

Execution

Plugins
Build tool
Filtering

Maven in Eclipse

2
What is Maven?

Maven is a project management tool which encompasses a project object model, a


set of standards, a project lifecycle, a dependency management system, and logic
for executing plugin goals at defined phases in a life cycle.

When you use Maven, you describe your project using a well-defined project object
model, Maven can then apply cross-cutting logic from a set of shared (or custom)
plugins.

3
Convention over Configuration

Maven is an attempt to apply patterns to a project's build infrastructure in order to


promote comprehension and productivity by providing a clear path in the use of best
practices.

4
What does Maven do?

● Maven is essentially a project management and comprehension tool and as such


provides a way to help with managing:
○ Builds
○ Documentation
○ Reporting
○ Dependencies
○ SCMs (Software configuration management)
○ Releases
○ Distribution

5
Installation

Maven comes pre-bundled in Eclipse

To use it independently:

● Download from https://maven.apache.org/download.html


● Follow the instructions in https://maven.apache.org/download.html#Installation

6
Creating a Project

mvn archetype:generate -DgroupId=com.mycompany.app


-DartifactId=my-app
-DarchetypeArtifactId=maven-archetype-quickstart
-DinteractiveMode=false

An archetype is defined as an original pattern or model from which all other things of
the same kind are made

7
Archetypes (predefined)

8
Standard Directory Layout

9
POM.XML

10
POM.XML

A SNAPSHOT version is the 'development'


version before the final 'release' version.
The SNAPSHOT is "older" than its release.

11
Dependencies

https://mvnrepository.com/
12
Build Lifecycles

Lifecycle = ordered sequence of phases.

There are three built-in build lifecycles: default, clean and site.

● The default lifecycle handles your project deployment,


● the clean life cycle handles project cleaning,
● while the site lifecycle handles the creation of your project's site documentation.

13
Default lifecycle common phases
● validate - validate the project is correct and all necessary information is available
● compile - compile the source code of the project
● test - test the compiled source code using a suitable unit testing framework. These
tests 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.
● verify - run any checks on results of integration tests to ensure quality criteria are met
● install - install the package into the local repository, for use as a dependency in other
projects locally
● deploy - done in the build environment, copies the final package to the remote
repository for sharing with other developers and projects

14
How do I compile my application sources?

15
How do I compile
my test sources
and run my unit
tests?

16
How do I create a JAR…

...and install it in my local repository?

17
Plugins
Maven is - at its heart - a plugin execution
framework; all work is done by plugins.

Build plugins will be executed during the build and


they should be configured in the <build/> element
from the POM.

Reporting plugins will be executed during the site


generation and they should be configured in the
<reporting/> element from the POM.
*configure the Java compiler to allow JDK 5.0 sources.
https://maven.apache.org/plugins/
18
Filtering
Sometimes a resource file will need to contain a value that can only be supplied at build
time. To accomplish this in Maven, put a reference to the property that will contain the
value into your resource file using the syntax ${<property name>}
Path of file: src/main/resources/application.properties

19
Maven & Eclipse
Let’s try it out!

20
References

Maven: The Complete Philosophy of Maven


Reference. V1.0. Sonatype, Maven by Example. V 0.7.
Inc. 2011 Sonatype, Inc. 2011 Maven in 5 Minutes

http://www.sonatype.com http://www.sonatype.com Maven Getting Started Guide

21
I keep six honest serving-men (They taught me all I knew);
Their names are What and Why and When And How and Where and Who.

Rudyard Kipling

22

You might also like