Maven
Maven
RAGHU
APACHE MAVEN
Maven is a free and open source software given by Apache Organization.
Maven is called as Java Build Tool.
Maven is used to perform Build Automation for java projects.
Note: Maven is used as a build tool for only java projects.
Why Maven?
To develop one java project we will use several frameworks like spring, hibernate.
We need to download those frameworks and we should add to our java project.
These frameworks we are using in our project are called as our project dependencies
Instead of we are downloading dependencies, we can tell to maven software to download
dependencies.
Note: Required dependencies we will add in "pom.xml" file then maven will download them.
pom stands for project object model.
When we create maven project then pom.xml file will be created automatically
pom.xml will act as input file for maven software
1|Page
Mr. RAGHU
(ESC :wq)
2|Page
Mr. RAGHU
MAVEN TERMINOLOGY:
archetype, groupId, artifactId, packaging, version
MAVEN REPOSITORY:
Maven will download dependencies using repository
In Maven we have 3 types of repositories
1) Central Repository: central repository is maintaining by apache organization
2) Remote Repository: Every organization will maintain their own remote repository
3) Local Repository: Local repository will be created in our system (C:/users/< username >/.m2
(or) /home/<username>/.m2)
When we add dependency in pom.xml, maven will search for that dependency in local
repository. If it is available it will add to project build path.
If dependency not available in local repository then maven will connect to Central
Repository or Remote Repository based on our configuration.
Note: By default maven will connect with central repository. If we want to use remote repository
then we need to configure remote repository details.
Note: Every software company will maintain their own remote repository (Ex: JFrog, Nexus)
MAVEN GOALS:
To perform project build activities maven provided several goals for us.
clean: clean goal is used to delete target folder
compile: compile goal is used to compile project source code. Compiled code will be stored in target
folder ( convert .java to .class)
test: test goal is used to execute unit test code of our application (JUnit code)
package: package goal is used to generate jar or war file for our application based on packaging type
available in pom.xml file. Jar or War file will be created in target folder.
install: install goal is used to install our project as a dependency in maven local repository.
Note: Every maven goal is associated with maven plugin. When we execute maven goal then
respective maven plugin will execute to perform the operation.
Syntax : mvn <goal-name>
Note: We need to execute maven goals from project folder (where pom.xml exist)
3|Page