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.
- How to create a Java project (JAR file)
- How to create a Java web application project (WAR file)
- How to create a 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
- Maven Profiles example
- Where is Maven Local Repository
- Where is Maven Central Repository
- Where is Maven Remote Repository
- Maven – How to enable proxy setting
- Maven – How to force re-download project dependencies?
- How to deploy Maven based war file to Tomcat
- How to include custom library into maven local repository?
Thank you so much for detailed explanation. it helped me a lot in setting up Maven and Junit.
HI,
My Name is Sarat, I am trying to crate a class in maven. I can’t create class. If i click the Finish button.It have’t response.Plz., HELP me
Hai i am newer to mavan i am facing a problem while set Home and Path in CMD prompt how to set that directly without system environmental section
You have to set maven in your class path, then you can check the same cmd prompt to confirm.
you are so wonderful
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 help on this?
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?
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 ??? Finally I have to generate a .war . Thanks .
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……
you have to set the maven in your , class path. Then just update your project.
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..
https://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!
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
constituent[24]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/sisu-inject-bean-2.3.0.jar
constituent[25]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/sisu-inject-plexus-2.3.0.jar
constituent[26]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/wagon-file-2.4.jar
constituent[27]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/wagon-http-2.4-shaded.jar
constituent[28]: file:/E:/ASF/apache-maven-3.0.5-bin/apache-maven-3.0.5/lib/wagon-provider-api-2.4.jar
—————————————————
Exception in thread “main” java.lang.UnsatisfiedLinkError: sun.nio.ch.IOUtil.iovMax()I
at sun.nio.ch.IOUtil.iovMax(Native Method)
at sun.nio.ch.IOUtil.(Unknown Source)
at sun.nio.ch.Util.(Unknown Source)
at sun.nio.ch.FileChannelImpl.(Unknown Source)
at java.io.FileInputStream.getChannel(Unknown Source)
at org.sonatype.aether.impl.internal.TrackingFileManager.read(TrackingFileManager.java:58)
at org.sonatype.aether.impl.internal.EnhancedLocalRepositoryManager.readRepos(EnhancedLocalRepositoryManager.java:144)
at org.sonatype.aether.impl.internal.EnhancedLocalRepositoryManager.find(EnhancedLocalRepositoryManager.java:69)
at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:307)
at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:216)
at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:193)
at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:281)
at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:186)
at org.sonatype.aether.impl.internal.DefaultRepositorySystem.readArtifactDescriptor(DefaultRepositorySystem.java:279)
at org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver.resolve(DefaultPluginDependenciesResolver.java:115)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getPluginDescriptor(DefaultMavenPluginManager.java:142)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getMojoDescriptor(DefaultMavenPluginManager.java:261)
at org.apache.maven.plugin.DefaultBuildPluginManager.getMojoDescriptor(DefaultBuildPluginManager.java:185)
at org.apache.maven.lifecycle.internal.DefaultLifecycleExecutionPlanCalculator.setupMojoExecution(DefaultLifecycleExecutionPlanCalculator.java:152)
at org.apache.maven.lifecycle.internal.DefaultLifecycleExecutionPlanCalculator.setupMojoExecutions(DefaultLifecycleExecutionPlanCalculator.java:139)
at org.apache.maven.lifecycle.internal.DefaultLifecycleExecutionPlanCalculator.calculateExecutionPlan(DefaultLifecycleExecutionPlanCalculator.java:116)
at org.apache.maven.lifecycle.internal.DefaultLifecycleExecutionPlanCalculator.calculateExecutionPlan(DefaultLifecycleExecutionPlanCalculator.java:129)
at org.apache.maven.lifecycle.internal.BuilderCommon.resolveBuildPlan(BuilderCommon.java:92)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
BTW,it works when I run it in prompt.
Any helps would be appreciated!
THX…
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????????
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] ————————————————————————
[INFO] Total time: 1 second
[INFO] Finished at: Thu May 02 11:47:01 IST 2013
[INFO] Final Memory: 1M/4M
[INFO] ————————————————————————
How to resolve this error?
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
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”, joinColumns={@JoinColumn(name=”BLOCKED_ID”)},
inverseJoinColumns=@JoinColumn(table=”USER”,name=”USER_ID”))
private Collection userlistId;
//getters and setters
}
Here is my User class:
Entity
@Table(name = “USER”)
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class User
{
@Id
@Column(name = “USER_ID”)
@GeneratedValue(strategy = GenerationType.AUTO)
@XmlElement
private int userid;
@Column(name = “FIRSTNAME”, nullable = true, unique = false)
@XmlElement
private String firstname;
@Column(name = “LASTAME”, nullable = true, unique = false)
@XmlElement
private String lastname;
//getters and setters
}
Or who can I do it with JPA?
Thanks
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………..
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.
thanks.learn a lot of things
Thanks a lot! Your tutorials helped me today!
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
Its really helpful for beginers
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
This is the correction for above comment;
I can not use
Thanks
The http link for the article “Generate javadoc jar for Maven based project” is wrong,you may be change it to https://mkyong.com/maven/generate-javadoc-jar-for-maven-based-project/
god of tutorials .. Detailed and simple steps explanation is awesome.. Keep it Up
Very nice piece of information at one location…thnx
You are the God of tutorials.. Helped me a lot in understanding maven..Thanks!!!
Thanks for your guidance. really Helpfull.
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.
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 my web application, and I want to rebuild the specific areas of changes rather than…. all the content.. i.e, If I change the JSPs then build that part and deploy and If I change XSL file build those files got modified and deploy rather than build everything .. How can i do that?
Thanks
Ram
If it is a java example I am looking for…then i look for mkyong.com.
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.
Thanks a lot! Your tutorials are great.
Hi,
I want to read the names of services for which i have given build?Please help me
Regards
Kiran
Thanks nice tutorial..
Thank you for your effort to put this together in a easy to read style.
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
it 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?