Maven 3 installation and configuration

In this tutorial we are going to show how to set up a working maven 3 installation.
Follow this steps:
- Download maven 3
- Install maven 3
- Configure maven 3
- Check setup


1. Download maven 3


- Navigate to http://maven.apache.org/download.html
- Download binary ZIP archive

2. Install maven 3


- Unpack ZIP archive to a directory of your choosing that suits your needs

3. Configure maven 3


We are going to configure our maven installation to use a custom repository directory.
- Create a directory for your repository
- Navigate to conf/settings.xml file of your maven installation
- Locate localRepository tag and change its value to a directory that you just created
- Add M2_HOME variable pointing to your maven installation
- Add bin directory of your maven installation to a PATH variable

4. Check setup


We are going to check if we can setup a simple test project with maven.
- Run a command line window – cmd command
- Enter following command

mvn archetype:create –DgroupId=com.itcuties –DartifactId=test

After maven downloads all the needed resources for executing this command a new test project is created.

12 Responses to "Maven 3 installation and configuration"

  1. Iman Syaefulloh says:

    Help me please, i’m noob i got this message “mvn is not recognized as an internal or external command” after i type this mvn archetype:create –DgroupId=com.itcuties –DartifactId=test

    Thanks

    Reply
    • itcuties says:

      It seems that maven’s bin directory is not added to your system’s PATH variable.
      Take care,
      itcuties

      Reply
  2. Karl says:

    Help when i run the command i get this error message:

    ERROR: JAVA_HOME not found in your environment. please set the java_home variable in your environment to match the location of your Java installation

    Thanks

    Reply
    • itcuties says:

      Hey Karl, you need to set the JAVA_HOME environment variable to point to the Java SDK installation. Do this…

      Under Linux/Other Unix:

      export JAVA_HOME=[PATH_TO_SDK_INSTALLATION_FOLDER]
      

      Under Windows:

      Start -> [right click] Computer -> Properties -> Advanced system settings -> Environment variables (button) -> New (button – set it for your user)
      We hope this helps! Take IT easy … and share our page with your friends! ;)

      Reply
  3. Rohit More says:

    Hello Admin,
    Actually I am also facing same problem . JAVA_HOME not set.
    even I set up JAVA_HOME variable and java and javac is working fine.
    but with mvn its not working . Same message is getting.

    Is there any configuration file where i need to put JAVA_HOME Path in maven Folder ?

    Reply
    • itcuties says:

      There is no magic with this configuration :) You have to have a mistake in you JAVA_HOME – where does it point? java and javac commands are working fine because you have added your Java’s bin folder to your PATH variable. Remember, when setting JAVA_HOME variable it should point to your Java installation folder and not to the bin folder like PATH variable does. Double check your JAVA_HOME setting. There has to be a typo or something :)

      Reply
  4. UzarCif says:

    Hey Admin,

    I have this Error:

    [ERROR] The goal you specified requires a project to execute but there is no POM
    in this directory (E:\MavenWorkspace). Please verify you invoked Maven from the
    correct directory. -> [Help 1]

    should i import a project containin a pom.xml file into the repo directory ?

    Reply
  5. Check setup - is not creating the project says:

    I tried to create the test project by running the Check set command given in step 4.
    Its showing the below error. Can you please suggest what is the error….

    —————————————————————————————————————————————————————

    c:\Web_Workspace>mvn archetype:create -DgroupId=com.itcuties -DartifactId=test
    [INFO] Scanning for projects…
    [INFO] ————————————————————————
    [INFO] BUILD FAILURE
    [INFO] ————————————————————————
    [INFO] Total time: 0.126s
    [INFO] Finished at: Thu Sep 25 16:33:24 BST 2014
    [INFO] Final Memory: 3M/15M
    [INFO] ————————————————————————
    [ERROR] The goal you specified requires a project to execute but there is no POM
    in this directory (c:\Web_Workspace). Please verify you invoked Maven from the
    correct directory. -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
    ch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please rea
    d the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProject
    Exception
    c:\Web_Workspace>

    I searched in Google and in few forums, its said that pom.xml is missing.
    Now this is not mentioned in any step to create .
    can you please suggest how to fix this ???

    Reply
  6. Kishore says:

    can please explain this cammand from the given above

    mvn archetype:create –DgroupId=com.itcuties –DartifactId=test
    
    Reply
  7. RAj says:

    How to install maven in MAC 10.11. i tried to install maven but when i entered like “mvn -version” i getting this error like sudo: mvn: command not found. Help me to solve this problem.

    Reply
  8. Yogesh Kumar says:

    Can you please help me out … I got an error, which says you need pom.xml in workspace folder. For more details here is the console output…

    D:\YogiWorkspace\MavenExample>mvn -e -X archetype:create -DgroupId=com.itcuties
    -DartifactId=test
    Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T22:59:2
    3+05:30)
    Maven home: C:\Apache\apache-maven-3.2.5
    Java version: 1.8.0_91, vendor: Oracle Corporation
    Java home: C:\Program Files (x86)\Java\jdk1.8.0_91\jre
    Default locale: en_US, platform encoding: Cp1252
    OS name: “windows 8.1″, version: “6.3″, arch: “x86″, family: “dos”
    [INFO] Error stacktraces are turned on.
    [DEBUG] Reading global settings from C:\Apache\apache-maven-3.2.5\conf\settings.
    xml
    [DEBUG] Reading user settings from C:\Users\YOGESH\.m2\settings.xml
    [DEBUG] Using local repository at C:\Apache\maven-repo
    [DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for C:\A
    pache\maven-repo
    [INFO] Scanning for projects…
    [DEBUG] Extension realms for project org.apache.maven:standalone-pom:pom:1: (non
    e)
    [DEBUG] Looking up lifecyle mappings for packaging pom from ClassRealm[plexus.co
    re, parent: null]
    [INFO] ————————————————————————
    [INFO] BUILD FAILURE
    [INFO] ————————————————————————
    [INFO] Total time: 0.095 s
    [INFO] Finished at: 2016-07-30T10:08:57+05:30
    [INFO] Final Memory: 4M/15M
    [INFO] ————————————————————————
    [ERROR] The goal you specified requires a project to execute but there is no POM
    in this directory (D:\YogiWorkspace\MavenExample). Please verify you invoked Ma
    ven from the correct directory. -> [Help 1]
    org.apache.maven.lifecycle.MissingProjectException: The goal you specified requi
    res a project to execute but there is no POM in this directory (D:\YogiWorkspace
    \MavenExample). Please verify you invoked Maven from the correct directory.
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(Lifecycl
    eStarter.java:80)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
    cher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
    a:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
    uncher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>