Maven Tutorial

Maven tutorials

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.

Maven Repository

Maven local, central and remote repository configuration and explanation, some terms you may need to understand before use Maven.

Maven based project and Eclipse IDE

Examples to create Java project and web application with Maven, and how to import it into Eclipse IDE.

Maven Basic Operations

Some basic operations, compile, build, unit test, install, generate site and deploy your Maven based project.

Maven FAQ

Some common Maven FAQs.

Maven Errors

Some common error messages in Maven.

Maven References

About the Author

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

Comments

Leave a Reply

avatar
newest oldest most voted
zapay
Guest
zapay

you are so wonderful

Garima
Guest
Garima
Hi, I am trying to integrate maven in eclipse indigo. But, the installation fails and give below issue: Cannot complete the install because one or more required items could not be found. Software being installed: m2e – Maven Integration for Eclipse (includes Incubating components) 1.8.0.20170516-2043 (org.eclipse.m2e.feature.feature.group 1.8.0.20170516-2043) Missing requirement: Maven Integration for Eclipse 1.8.0.20170516-2043 (org.eclipse.m2e.core 1.8.0.20170516-2043) requires ‘bundle org.eclipse.osgi 3.10.0’ but it could not be found Cannot satisfy dependency: From: m2e Marketplace 1.8.0.20170516-2043 (org.eclipse.m2e.discovery 1.8.0.20170516-2043) To: bundle org.eclipse.m2e.core [1.8.0,1.9.0) Cannot satisfy dependency: From: m2e – Maven Integration for Eclipse (includes Incubating components) 1.8.0.20170516-2043 (org.eclipse.m2e.feature.feature.group 1.8.0.20170516-2043) To: org.eclipse.m2e.discovery [1.8.0.20170516-2043] Can anyone… Read more »
Tarun Kumar
Guest
Tarun Kumar

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.

Juan
Guest
Juan

Hello,how to work with webfragments and maven?

Vivek
Guest
Vivek
I have a use case … I am building a website. Depending on the user login I want to build an other application (which is an second project in Eclipse) (all this in real time) ( this I want to accomplish through Maven Eclipse plugin)? How can I achieve this? So my specific question is —- From one project (website project) in eclipse , how to call (how to build , generate its exe, mvn install ) a second project? ….. Do I have to call Runtime.getRuntime().exec(“… but then how do I give the address of the second project ???… Read more »
Daxi Li
Guest
Daxi Li

You are the best!

neetu
Guest
neetu

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

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……

Srinivas Nudurupati
Guest
Srinivas Nudurupati

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..

Mahadev Shinde
Guest
Mahadev Shinde
Radhakrishna
Guest
Radhakrishna

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

Radhakrishna
Guest
Radhakrishna

ECLIPSE KEPLER AND STS 3.4.O are killing me like anything. Could you help me please?

Radhakrishna
Guest
Radhakrishna

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

DevRaj
Guest
DevRaj

Great Tutorial….
Dev

Prasanth Prabhakaran
Guest
Prasanth Prabhakaran

Really awesome… Keep it up…

Gaurav
Guest
Gaurav

Amazingly practical knowledge presented in practical terms! :)

Gamola
Guest
Gamola

? ????? MKYONG

Gamola
Guest
Gamola

MKYONG ????????? ????? ????? ???? ???????!

Malathi
Guest
Malathi

Hi,

Thanks for this tutorials .It is very simple to learn and achieves everything which we need

Amol
Guest
Amol

Thanks.Very helpful

Laura
Guest
Laura

Your tutorials are so simple and yet covers all that matters…
Thank you very much!

Benson
Guest
Benson
Hey,mkyong.May I ask you a question? I created a Maven Project using maven-archetype-quikstart plugin in Eclipse 4.2.2. When I right click the pom.xml and run mvn test command,what I saw in console is the following: [INFO] Scanning for projects… [INFO] [INFO] ———————————————————————— [INFO] Building Maven Hello World Project 1.0-SNAPSHOT [INFO] ———————————————————————— ————————————————— constituent[0]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/aether-api-1.13.1.jar constituent[1]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/aether-connector-wagon-1.13.1.jar constituent[2]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/aether-impl-1.13.1.jar constituent[3]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/aether-spi-1.13.1.jar constituent[4]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/aether-util-1.13.1.jar constituent[5]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/commons-cli-1.2.jar constituent[6]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/maven-aether-provider-3.0.5.jar constituent[7]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/maven-artifact-3.0.5.jar constituent[8]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/maven-compat-3.0.5.jar constituent[9]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/maven-core-3.0.5.jar constituent[10]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/maven-embedder-3.0.5.jar constituent[11]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/maven-model-3.0.5.jar constituent[12]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/maven-model-builder-3.0.5.jar constituent[13]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/maven-plugin-api-3.0.5.jar constituent[14]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/maven-repository-metadata-3.0.5.jar constituent[15]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/maven-settings-3.0.5.jar constituent[16]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/maven-settings-builder-3.0.5.jar constituent[17]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/plexus-cipher-1.7.jar constituent[18]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/plexus-component-annotations-1.5.5.jar constituent[19]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/plexus-interpolation-1.14.jar constituent[20]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/plexus-sec-dispatcher-1.3.jar constituent[21]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/plexus-utils-2.0.6.jar constituent[22]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/sisu-guava-0.9.9.jar constituent[23]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/sisu-guice-3.1.0-no_aop.jar… Read more »
satish
Guest
satish

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????????

Meenu Khurana
Guest
Meenu Khurana
whenver I try to use any MVN command i get the following error. C:\>mvn eclipse:eclipse -Dwtpversion=1.5 [INFO] Scanning for projects… [INFO] Searching repository for plugin with prefix: ‘eclipse’. [INFO] org.apache.maven.plugins: checking for updates from central [WARNING] repository metadata for: ‘org.apache.maven.plugins’ could not be retri eved from repository: central due to an error: Error transferring file: Connecti on refused: connect [INFO] Repository ‘central’ will be blacklisted [INFO] ———————————————————————— [ERROR] BUILD ERROR [INFO] ———————————————————————— [INFO] The plugin ‘org.apache.maven.plugins:maven-eclipse-plugin’ does not exist or no valid version could be found [INFO] ———————————————————————— [INFO] For more information, run Maven with the -e switch [INFO] ————————————————————————… Read more »
Praveen Kumar
Guest
Praveen Kumar

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.

Anonymous
Guest
Anonymous

Can you message me with some hints on how you made this web site look this cool, I??d be thankful.

yacoubi
Guest
yacoubi

Please can i find here maven+ hibernate/facetsJPA/spring3+jsf

Matt
Guest
Matt

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

iraj
Guest
iraj
I want to create a table as below: | ID | BlockerID | BlockedID | | 1 | 5 | 6 | | 2 | 5 | 7 | | 3 | 5 | 8 | | 4 | 5 | 10 | | 5 | 9 | 5 | So 5 has blocked 6, 7, 8, 10 and 9 has blocked 5. Is possible to do thins like this: @Entity @Table(name=”BLOCKEE”) @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class Blockee { @Id @GeneratedValue(strategy= GenerationType.AUTO) @Column(name=”BLOCKEE_ID”) @XmlElement private int blockeeid; @OneToMany(cascade= {CascadeType.PERSIST, CascadeType.MERGE}) @JoinTable(name=”BLOCKEE”, joinColumns= {@JoinColumn(name=”BLOCKER_ID”)}, inverseJoinColumns=@JoinColumn(table=”USER”,name=”USER_ID”)) private User userid; @OneToMany(cascade= {CascadeType.PERSIST, CascadeType.MERGE}) @JoinTable(name=”BLOCKEE”,… Read more »
Naresh
Guest
Naresh

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).

mamu
Guest
mamu

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