Apache Maven Tutorial

Apache Maven, is an innovative software project management tool. It uses a project object model (POM) file to manage project’s build, dependencies, reporting and documentation.

P.S Tested with Apache Maven 3.5.x

1. Installation

Install Maven on Windows, Ubuntu and MacOS

2. Java Project

Maven examples to manage JAR project, Web project (WAR) and multi module project.

3. Unit Test

Maven + JUnit 5 examples.

4. Code Coverage

Maven + Code coverage report integration.

5. Static Code Analysis

Maven + Static code analysis report.

6. Maven FAQs

=> See all Maven articles

Source Code

References

  1. Maven in 5 Minutes
  2. Maven Standard Directory Layout
  3. Maven by Example
  4. Wikipedia – Apache Maven

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
58 Comment threads
6 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
59 Comment authors
saratVenkatesan.SzapayGarimaTarun Kumar Recent comment authors
newest oldest most voted
Sunil HR
Guest
Sunil HR

i am newer to maven…i am facing a problem while creating new maven
project it throws an below error….

CoreException:
Could not calculate build plan: Plugin
org.apache.maven.plugins:maven-compiler-plugin:2.3.2 or one of its
dependencies could not be resolved: Failed to read artifact descriptor
for org.apache.maven.plugins:maven-compiler-plugin:jar:2.3.2:
ArtifactResolutionException: Failure to transfer
org.apache.maven.plugins:maven-compiler-plugin:pom:2.3.2 from http://repo.maven.apache.org/m
was cached in the local repository, resolution will not be reattempted
until the update interval of central has elapsed or updates are forced.
Original error: Could not transfer artifact
org.apache.maven.plugins:maven-compiler-plugin:pom:2.3.2 from/to central
(http://repo.maven.apache.org/m… null to http://repo.maven.apache.org/m

kindly reply as soon as possible……

Daxi Li
Guest
Daxi Li

You are the best!

zapay
Guest
zapay

you are so wonderful

Jim
Guest
Jim

Hey,

Just a question about maven which has cropped up in the mkyong hibernate tutorial:

I know tutorials require effort to keep up-to-date so this is not a critical comment.

When I get a message such as:


Unable to find resource 'hibernate:hibernate3:pom:3.2.4.ga' in repository central (http://repo1.maven.org/maven2)

What am I supposed to do about it? It doesn’t say whether or not I’m supposed to do anyhting to fix it or that it is okay to proceed as is.

addicted_guy
Guest
addicted_guy

mkyong hattsoff to you man, i appreciate your effort to opensource your thoughts and tutorials, immense thanks to you 🙂

take care

Dhayanidhi
Guest
Dhayanidhi

Hi,

I am new to Maven. I am using Maven3.0.
Your tutorials are good.
Could you please suggest what is the option number I need to choose to generate folder structure for java project in maven 3.0?

Thanks And Regards
Dhaya

MarwaGamal
Guest
MarwaGamal

thanks a lot for your effort .

i have a semi problem , my archetype local catalog is empty , so when i try

  mvn archetype:generate 

it shows only the remote repository templates

when i force using local repository

  mvn archetype:generate -DarchetypeCatalog=local 

no thing shows up , there isn’t any template there

so what could i do ??
thanx in advance

irobertyu
Guest
irobertyu

I think the main thing to use dependency management of maven is like that,
1, install maven plugin
2, set local repository in .m2/setting.xml and activate it.
3, click ‘mvn test’ to download dependency library automatically.

salman
Guest
salman

Hello Mr Young,

I am doing as instructed.On the command line i see maven downloading dependencies.But in the end i am not able to find any jar files in local repository.Please suggest a resolution for this.

Many Thanks

Maven Video Tutorial
Guest
Maven Video Tutorial

Thank you for these tutorials .
Maven is a powerful project management tool.

Albert
Guest
Albert

Great style, right to the point. Will save it as a good reference for Maven. Thank you heaps for your efforts.

Michael
Guest
Michael

Thank you for your effort to put this together in a easy to read style.

killer
Guest
killer

Thanks nice tutorial..

kiran
Guest
kiran

Hi,

I want to read the names of services for which i have given build?Please help me

Regards
Kiran

zhanglongyang
Guest
zhanglongyang

Thanks a lot! Your tutorials are great.

optimization
Guest
optimization

Valuable information. Lucky me I discovered your site by accident, and I’m shocked why this twist of fate did not happened in advance! I bookmarked it.

Loknath Reddy
Guest
Loknath Reddy

If it is a java example I am looking for…then i look for mkyong.com.

Ram
Guest
Ram

Hi Mkyong, Superb work !! These are masterpieces !! Thanks for writing all these articles and these will certainly help the development community and we have very less time digging the specifications published by these Opensource development teams !! Keep doing the work! I appreciate if you can publish your ideas on designing the webservices concepts (i mean the desing issues like performance, scalability, availability and standard approaches for services design etc)… And finally, coming to build, I liked these articles but wanted to ask you one questions…. Suppose If I have some JSPs, Java files, XLS files etc in… Read more »

jainy
Guest
jainy

Hi mkyong,
I did setting for Maven following your previous tutorials,but when i run this goal “mvn archetype:generate” in command window, build failed showing
[ERROR] No plugin found for prefix ‘archetype’ in the current project and in the
plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the….

Have checked proxy settings in “Internet Options” but there was nothing,have stucked here .
Please tell me some solution so that I can go forward.

Thanks.

Prasad Chande
Guest
Prasad Chande

Thanks for your guidance. really Helpfull.

Nitin
Guest
Nitin

You are the God of tutorials.. Helped me a lot in understanding maven..Thanks!!!

Rakesh Sharma
Guest
Rakesh Sharma

Very nice piece of information at one location…thnx

Bhushan
Guest
Bhushan

god of tutorials .. Detailed and simple steps explanation is awesome.. Keep it Up

snowdream
Guest
snowdream

The http link for the article “Generate javadoc jar for Maven based project” is wrong,you may be change it to http://www.mkyong.com/maven/generate-javadoc-jar-for-maven-based-project/

Sheeraz
Guest
Sheeraz

Hi mate,

Just want to know that how can I deploy artefacts using -DaltResposiory=releaseRespotirt::::http://abc.com, the problem is that I do not know what to provide for ‘layout’ value? I have around 16 projects and I ant to deploy all one by one and can not use as I want to control my deployment via settings.xml. I have defined two repository ‘releaseRepository’ and ‘snapshotRepository’ and want to switch at build time via parameters passed. Your comments will be appreciated.

Thanks,

Sheeraz

Rakesh Kumar Mohanty
Guest
Rakesh Kumar Mohanty

This Side Save my Job Some times because it really helps in understanding the concept and then the person in good touch to implement the concepts.Thanks

Luiz Valença
Guest
Luiz Valença

Thanks a lot! Your tutorials helped me today!

Alex.Chen
Guest
Alex.Chen

thanks.learn a lot of things

dli7mar
Guest
dli7mar

Can I put maven pom jars into a folder in Eclipse? My pom jars are in the root of the project, it’s not good for the layout, especially when I have many jars.

Thanks.

mamu
Guest
mamu

good work it is really helpfull us………..