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.
- 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?
Source Code
$ git clone https://github.com/mkyong/maven-examples
You are the best!
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.
you are so wonderful
Hello,how to work with webfragments and maven?
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
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.
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.
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 .
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 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