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
Leave a Reply
you are so wonderful
Regarding Custom Library.
we are using Maven. One of the custom library reside under web-inf/lib dir. while building project i m facing error like
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project : Compilation failure: Compilation failure: saying that cannot find symbol.
above mentioned lib are not mentioned under pom.xml.
can you please help me.
Hello,how to work with webfragments and maven?
You are the best!
I am planning to write a custom rule extending maven enforcer
plugin. My task is simple here. I need to read the description in the
POM file and see if it valid or not and fail the build of the project if
it is empty. Can anyone help me how to retrieve the descrioption and
check using java code
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……
I am getting the following error when i try to integarate maven in eclipse.
Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5
Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5
Please help me ASAP..
http://www.mkyong.com/maven/generate-javadoc-file-for-maven-based-project/ got 404, check it out
Even if i downloaded the new eclipse kepler, i am getting the following error-
Could not calculate build plan: Plugin org.apache.maven.plugins:maven-war-plugin:2.1.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-war-plugin:jar:2.1.1
Plugin org.apache.maven.plugins:maven-war-plugin:2.1.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-war-plugin:jar:2.1.1
ECLIPSE KEPLER AND STS 3.4.O are killing me like anything. Could you help me please?
Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5
Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5
Great Tutorial….
Dev
Really awesome… Keep it up…
Amazingly practical knowledge presented in practical terms! :)
? ????? MKYONG
MKYONG ????????? ????? ????? ???? ???????!
Hi,
Thanks for this tutorials .It is very simple to learn and achieves everything which we need
Thanks.Very helpful
Your tutorials are so simple and yet covers all that matters…
Thank you very much!
Hai mkyong, this satish developing web application using spring3 mvc and Hibernate with maven and jboss,I’m configuring all the dependecies in pom.xml but my problem is how to configure jboss4.2.3 in pom.xml using maven 2.x to deploy the web application war file in jboss server deploy folder automatically.? Can you guide me Regarding this post????????
Everything in maven done through plugins.And “org.apache.maven.plugins:maven-eclipse-plugin” is not available in your repository. To solve this issue, try to point remote reopsitory( configure it in settings.xml in maven installed dir),so that maven can download required plugins from from remote repositories.
Can you message me with some hints on how you made this web site look this cool, I??d be thankful.
Please can i find here maven+ hibernate/facetsJPA/spring3+jsf
I actually Feel posting, _Maven Tutorial_ was good!
I actuallycan’t see eye to eye together with u more! Finally looks like Istumbled upon a blog truly worth browsing. I appreciate it, Cynthia
mvn site:stage related configuration and examples, as I’m running automation test cases and the cases are executing multiple time(i.e two times).
good work it is really helpfull us………..