Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Introduction to Apache
Rajind Ruparathna
AdroitLogic
Outline
● What is Maven?
● Download and Installation
● Configuring Maven
● First Maven Project
● What is a POM?
● Using Ex...
What is Maven?
Maven is essentially a project management tool and as such provides a way to
help with managing:
● Builds
●...
Download and Installation https://maven.apache.org/download.cgi
4
Configuring Maven
Maven configuration occurs at 3 levels:
● Installation - this is configuration added once for a Maven in...
Configuring your Local Repository
The location of your local repository can be changed in your user configuration.
The def...
Configuring Security and Deployment Settings
7
First Maven Project
To create our first Maven project we are going to use Maven's archetype
mechanism.
An archetype is def...
First Maven Project contd.
9
What is a POM? - Project Object Model
● It is an XML file that contains information about the project and configuration
de...
What is a POM? contd.
XML
Artifact Descriptor
Hierarchy
Dependencies
11
Using External Dependencies
● Transitive Dependencies
○ Excluded/Optional Dependencies
● Dependency Scope
● Dependency Man...
Transitive Dependencies
There are two types of Maven
dependencies:
● Direct: These are dependencies defined
in your pom.xm...
Dependency Scope
Dependency scope is used to limit the transitivity of a dependency, and also to
affect the classpath used...
Dependency Scope contd.
runtime
This scope indicates that the dependency is not required for compilation, but is for
execu...
Dependency Exclusions
Since maven resolves dependencies
transitively, it is possible for
unwanted dependencies to be
inclu...
Project Lifecycle Management
Compiling application sources - mvn compile
Compile test sources and run unit tests - mvn tes...
Using External Repositories
A repository in Maven is used to hold
build artifacts and dependencies of
varying types.
There...
Using Plugins
Whenever you want to customise the
build for a Maven project, this is done
by adding or reconfiguring plugin...
References
https://maven.apache.org/guides/getting-started/index.html
20
Upcoming SlideShare
Loading in …5
×

Introduction to Apache Maven

1,536 views

Published on

Getting started with Apache Maven

What is Maven?
Download and Installation
Configuring Maven
First Maven Project
What is a POM?
Using External Dependencies
Project Lifecycle Management
Using External Repositories
Using Plugins

https://notebookbft.wordpress.com/

Published in: Software
  • Be the first to comment

Introduction to Apache Maven

  1. 1. Introduction to Apache Rajind Ruparathna AdroitLogic
  2. 2. Outline ● What is Maven? ● Download and Installation ● Configuring Maven ● First Maven Project ● What is a POM? ● Using External Dependencies ● Project Lifecycle Management ● Using External Repositories ● Using Plugins 2
  3. 3. What is Maven? Maven is essentially a project management tool and as such provides a way to help with managing: ● Builds ● Documentation ● Reporting ● Dependencies ● SCM ● Releases ● Distribution 3
  4. 4. Download and Installation https://maven.apache.org/download.cgi 4
  5. 5. Configuring Maven Maven configuration occurs at 3 levels: ● Installation - this is configuration added once for a Maven installation ● User - this is configuration specific to a particular user ● Project - most static configuration occurs in pom.xml You can specify your user configuration in ${user.home}/.m2/settings.xml. ● Configuring your Local Repository ● Configuring a Proxy ● Security and Deployment Settings 5
  6. 6. Configuring your Local Repository The location of your local repository can be changed in your user configuration. The default value is ${user.home}/.m2/repository/. Note: The local repository must be an absolute path. 6
  7. 7. Configuring Security and Deployment Settings 7
  8. 8. First Maven Project To create our first Maven project we are going to use Maven's archetype mechanism. An archetype is defined as an original pattern or model from which all other things of the same kind are made. mvn -B archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=my-app 8
  9. 9. First Maven Project contd. 9
  10. 10. What is a POM? - Project Object Model ● It is an XML file that contains information about the project and configuration details used by Maven to build the project. 10
  11. 11. What is a POM? contd. XML Artifact Descriptor Hierarchy Dependencies 11
  12. 12. Using External Dependencies ● Transitive Dependencies ○ Excluded/Optional Dependencies ● Dependency Scope ● Dependency Management 12
  13. 13. Transitive Dependencies There are two types of Maven dependencies: ● Direct: These are dependencies defined in your pom.xml file under the <dependencies/> section. ● Transitive: These are dependencies that are dependencies of your direct dependencies. 13
  14. 14. Dependency Scope Dependency scope is used to limit the transitivity of a dependency, and also to affect the classpath used for various build tasks. compile This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects. provided This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. This scope is only available on the compilation and test classpath, and is not transitive. 14
  15. 15. Dependency Scope contd. runtime This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath. test This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases. This scope is not transitive. system This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository. 15
  16. 16. Dependency Exclusions Since maven resolves dependencies transitively, it is possible for unwanted dependencies to be included in your project's classpath. Therefore explicit dependency exclusion can be used. Excluded artifacts will not be added to your project's classpath. 16
  17. 17. Project Lifecycle Management Compiling application sources - mvn compile Compile test sources and run unit tests - mvn test Creating a JAR and installing it in my local repository - mvn package -mvn install Removing the target directory -mvn clean 17
  18. 18. Using External Repositories A repository in Maven is used to hold build artifacts and dependencies of varying types. There are strictly only two types of repositories: local and remote Offline: mvn -o package Force Update: mvn install -U 18
  19. 19. Using Plugins Whenever you want to customise the build for a Maven project, this is done by adding or reconfiguring plugins. For this example, we will configure the Java compiler to allow specific java version ({java.version}) sources. 19
  20. 20. References https://maven.apache.org/guides/getting-started/index.html 20

×