Maven
Maven is a Build tool
Maven provides
-> Compile the source code.
-> Generate jar, war, ear.
-> Deployment
-> Generate the reports like code quality, code coverage.
-> Generate the documentation.
Maven’s project goal
Maven's primary goal is to allow a developer to understand the complete state of a project in the shortest period of time.
Maven’s Objectives
- It makes the build process easy.
- Provides a uniform building system.
- Provides quality related project information .
- Provides guidelines related to development to meet the best goal.
- Allows transparent migration to new features.
Maven’s Features
- Superior dependency management.
- A large repository of libraries and metadata.
- Multiple projects handling.
- Extensible, easy to write plug-in.
- Coherent site of project information.
- Multiple language support – C++, Java …
- Maintainability: stop building the build. Focus on the application.
2) Maven Software Installation :
-> It is an opensource software
-> It is in the form of zip file
-> Download maven.zip freely from http://apache.osuosl.org/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.zip
After extracting the maven zip file, the maven root folder will be having
bin -> mvn.bat
conf -- settings.xml
lib -- jar
plugins - predefined.
-> Latest version : 3.5.x
from 3.3 -- JDK 1.7 or above is using
< maven 3.3 -- jdk 1.6 is using.
Note : Q) How to enable maven software ?
Maven is completely written in java, so it must compatible with the respective Java version
In windows operating systems - > Properties -> settings ->environment variables set below
JAVA_HOME = C:\Program Files\Java\jdk1.8.0_131
Path = C:\Program Files\Java\jdk1.8.0_131\bin or %JAVA_HOME%/bin
Maven project structure
2) Importance of pom.xml
A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project.
--> Pom stands for project objective model.
-> It contains information about how to generate jar, war, ear and also how to generate the reports like codequality, code coverage..
-> Every pom.xml have 3 elements are mandatory.
1. Groupid - group name for jar, war, ear
2. Artifactid - jar or war or ear name
3. Version -- version of jar or war
Examples :
---------------
com.dev21(Groupid) : FirstApp(Artifactid) : 1.0-SNAPSHOT ( version)
Always the combination should be unique.
------------
<project>
<groupid>com.dev21</groupid>
<artifcatid>FirstApp</artifactid>
<version>1.0-SNAPSHOT</version>
<packaging> jar or war or ear or pom
</packaging>
</project>
Maven command operations
Types of Repositories :
1. Local Repository -- C:\Users\Sreenu\.m2
2. Remore Repository - client rep -- https://www.repo.hdfc.com/archive/project
3. Central Repository - https://repo.maven.org/artifacts/projects/..
Note : When we run the maven project first maven will look into local repo to find the dependencies.
If it is found then get from local rep.
--> If it is not found in local repo then it will go central repo, if it is found in central then get the dependencies from central repo.
--> If it is not found in central repo then it will go remote repo, if it is find in remote repo then get the dependencies from remote repo else it will give error no artifact found.
8) Importance of settings.xml
--> settings.xml file will configure locations of local repo and remote repo.
--> First maven software will read the pom.xml and start the search in local repo which is configured in settings.xml file.
--> The default local rep location : C:\Users\Sreenu\.m2 if you want we can update the new local repo location in settings.xml
--> maven software will refere new local repo instead of
9) Types of pom.xml
a) Normal pom.xml
b) Parent pom.xml
c) Super pom or Effective pom.xml
d) Aggregator pom or modules pom
Aggregator or modules pom.xml
Maven is the most popular Java Dependency Management Tool.
Thanks for referring this article, well, you may get much knowledge/learn all below areas by end of this article.
- Use Maven to Manage Dependencies
- Use Maven to create Multi Module Projects
- Understand Maven Best Practices
- Use Maven Commands
- Understand Maven Build Life Cycle and Project Object Model
- Understand Maven's philosophy of "Convention over Configuration"
- Use Maven to generate Projects using Maven Archetypes
- Use Maven Plugins
- Understand how to use Maven in combination with an IDE like Eclipse
We can automate all below listed ones using Maven :
- Compiling Java Code
- Running Unit Tests
- Building Jar's and Wars
- Running web applications in Tomcat
- Setting up new projects
Let's build some sample projects using below important Maven :
- Dependency Management - including Transitive Dependencies
- Maven Project Object Model
- Maven Build Life Cycle
- Maven Plugins
- Maven Archetypes - Generate Projects
- Maven Best Practices
- Multi Module Maven Projects
Target audience?
- You want to use Maven to manage Dependencies
- You want to use Maven to create New Projects
- You have familiarity with Java Programming
- You want to understand Maven Best Practices and a few Maven Tips and Tricks
- You want to understand how Maven Works
Requirements
- You should have familiarity with Java Programming.
- You should have access to internet to download and setup Maven and Eclipse
- We will help you setup Maven and Eclipse
- You should be ready to have fun doing a lot of hands-on stuff
Topics
1) Maven Basics
a : Magic of Maven - How does it help a developer?
b : Setting up Your First Maven Project
c : Your First Maven Dependency
d : Understand How to Build a Jar
e : Maven Goals - compile, test and install
f : Understand Maven Build Life Cycle
2) Maven Dependency Management
- Understand Maven POM - Project Object Model
- Transitive Dependencies
- Excluding Dependencies in Maven
- Scope of a Dependency
- Versioning of Dependencies
3) How does Maven Work?
4) Advanced Maven
- Maven Super POM and Effective POM - Convention over Configuration
- Understand How Maven Downloads dependencies - effective-settings
- Let's Play with Maven Plugins
- Maven from Command Line
- Basics of Multi Module Maven Project
- Best Practices of Multi Module Maven Project
- Running Web Application in Tomcat
- Maven Commands - Tips and Tricks
- Creating Projects with Maven Archetypes
5) Conclusion
No comments:
Post a Comment