Maven Tutorial

Apache Maven, is an innovative software project management tool, provides new concept of a project object model (POM) file to manage project’s build, dependency and documentation. The most powerful feature is able to download the project dependency libraries automatically.
In this tutorials, it provides many step by step examples and explanations on using Apache Maven 2.x.
Happy learning Maven. ![]()
Maven Installation & Configuration
Installation guide on Windows and Ubuntu.
- Install Maven on Windows
Article about how to install Maven on Windows. - Install Maven on Ubuntu
Article about how to install on Ubuntu. - Enable proxy access in Maven
To use proxy server to connect internet, you have to configure the proxy setting in Maven.
Maven Repository
Maven local, central and remote repository configuration and explanation, some terms you may need to understand before use Maven.
- What is Maven local repository
Maven local repository is used to store the project dependency libraries, and the default folder is “.m2″, you may need to change it to another folder. - What is Maven central repository
Maven central repository is the default location for Maven to download all the project dependency libraries. - What is Maven remote repository, and how to configure it
Not all libraries are store in Maven central repository, often times, you need to add some remote repositories to download the libraries from another location instead of the default central repository. - Maven library dependency explanation
Article about the different of dependency library in tradition way and Maven way, and explains where Maven will search those library. - Install custom library into Maven local repository
Many libraries are still not support Maven pom.xml concept, here’s a guide to show how to include the “non-maven-support” library into Maven local repository.
Maven based project and Eclipse IDE
Examples to create Java project and web application with Maven, and how to import it into Eclipse IDE.
- Create a Java project with Maven
Uses Maven to create a Java project. - Convert Maven based Java project to support Eclipse IDE
Guide to convert Maven based Java project to support Eclipse IDE. - Create a Web Application Project with Maven
Uses Maven to create a Web Application Project. - Convert Maven based web application to support Eclipse IDE
Guide to convert Maven based web application to support Eclipse IDE. - Create a project with Maven template
Alternatively, you can create a standard project from Maven templete. - Convert existing Java web project to Maven based project
Guide to convert existing Java web project to Maven based web application project, and support Eclipse IDE.
Maven Basic Operations
Some basic operations, compile, build, unit test, install, generate site and deploy your Maven based project.
- How to build project with Maven
“mvn package” to build project. - How to clean project with Maven
“mvn clean” to clean project. - How to run unit test with Maven
“mvn test” to run unit test. - How to install your project into Maven local repository
“mvn install” to package and deploy project to local repository. - How to generate a documentation site for your Maven based project
“mvn site” to generate documentation site for your project information. - How to deploy site with “mvn site-deploy” – WebDAV example
“mvn site-deploy” to deploy generated documentation site to server automatically, via WebDAV. - How to deploy Maven based war file to Tomcat
“mvn tomcat:deploy” to deploy WAR file to Tomcat.
Maven FAQ
Some common Maven FAQs.
- Add M2_REPO classpath variable to Eclipse IDE
To make your Maven project support Eclipse IDE, you need to add this M2_REPO classpath variable. - How to display Maven plugin goals and parameters
Use Maven to diplsay all available goals and parametera of a plugin. - Integrate Maven with Eclipse via External Tool Configuration
How to integrate Maven with Eclipse IDE. - Skip unit test during Maven build
Tip to skip running your unit test in Maven. - Change Maven resources folder location
A guide to show how to add another resource folder to your Maven’s project. - Search Maven coordinates (dependency) with Google
How do you know the library Maven coordinate? Search it folder by folder on Maven repository? Here’s a tip to use Google site search to get the Maven coordinate from Maven repository. - Create Ant build file from Maven pom.xml
A plugin to generate Ant build file (build.xml) from Maven’s pom.xml file. - Generate source code jar for Maven based project
Uses “maven-source-plugin” to pack your source code and deploy along with your project. - Generate javadoc jar for Maven based project
Uses “maven-javadoc-plugin” to generate javadoc jar and deploy along with your project. - Download J2EE API (javaee.jar) via Maven
- Download JavaMail API via Maven
- Download standard.jar (taglib) & jstl.jar via Maven
Maven Errors
Some common error messages in Maven.
- Maven dependency libraries not deploy in Eclipse IDE
- Unsupported WTP version: 1.5
- Annotations are not supported in -source 1.3
- Tomcat deploy Maven project web.xml to a wrong folder in Eclipse
- Maven + WebDAV – Embedded error: Failed to transfer file: … Return code is: 405
Maven References
- Apache Maven official tutorials
- Apache Maven (Wiki)
- http://maven.apache.org/guides/mini/guide-ide-eclipse.html
- http://maven.apache.org/archetype/maven-archetype-plugin/generate-mojo.html
- http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
Great style, right to the point. Will save it as a good reference for Maven. Thank you heaps for your efforts.
Thank you for these tutorials .
Maven is a powerful project management tool.
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
When you use Maven to build your project, it will download the dependencies that declared in your project
pom.xmlFor example, if you are using Eclipse, uses “
mvn eclipse:eclipse“@salman
thanks mkyong for helping us out with these tutorial.
i shall answer to this question with your permission ,actually all the dependencies are combined together and stored in common jar format.
when you install the dependencies by mvn install it looks in some of the maven repositories and installs the respective dependencies.
now if your requirement is to see all the dependencies in common folder use this command
“mvn dependency:copy-dependencies”
this will store all the dependencies in your target/dependency folder.
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.
thanks a lot for your effort .
i have a semi problem , my archetype local catalog is empty , so when i try
mvn archetype:generateit shows only the remote repository templates
when i force using local repository
no thing shows up , there isn’t any template there
so what could i do ??
thanx in advance
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
mkyong hattsoff to you man, i appreciate your effort to opensource your thoughts and tutorials, immense thanks to you
take care
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.
Mind to share me your Maven’s hibernate coordinate in pom.xml?