03. ♥ Setting up Maven step by step tutorial

This is mainly for the beginners of Java to get started with Maven. This is required not only for learning Java, but also conducive to creating your self-taught Java projects. Extends Setting up Java step by step tutorial. This is an industrial strength tool to build Java applications.

Install Maven

Maven is a build, dependency management (i.e. jar files dependency) and deployment tool.

Step 1: Download and install Maven from:


Download the binary “zip” file “apache-maven-3.5.0-bin.zip” if in Windows or the “apache-maven-3.5.0-bin.tar.gz” if in Unix, and unpack them into the “tools” folder.

Install Maven

Step 2: Configure the environment variables “M3_HOME” and “path”. For example


Previously in Java installation tutorial “environment-setup.cmd” was created under “c:\scripts”. Add Maven environment settings to that file.

Run the script:

On Unix

type the following in “.profile”

Verify installation

Once maven has been set up correctly, you should be able to verify it by

also, “where” in DOS and “which” in Unix.

Configure Maven

You can set up the repository location by opening the settings.xml file under conf folder inside your maven installation directory “c:\tools\apache-maven-3.5.0-bin\apache-maven-3.5.0\conf”. Repository is where the dependency Java libraries will be stored.

Rename the settings.xml to settings.xml_old, and create a new “settings.xml” as shown below with a basic config.

Local Repository

Are you behind a firewall?

If your internet access requires proxy settings, you need have that added to your settings.xml file.

Create a Maven project

A maven project is nothing but a Java project as we saw earlier with a predefined structure. Maven follows a certain convention in terms of the directory structure.

Step 1: Create a Java project using Maven. “com.mytutorial” is a package inside “src/main/java”.

Step 2: “pom.xml” file looks as shown below.

The pom.xml file is where you define the dependent libraries like “hibernate”, “spring”, “junit”, etc. Change the version to the latest possible. For example: “4.9” as per


You can also search at


prefix it with “g:” for group as in “g:junit”, and “a:” for artifact id as in “a:junit”.

Step 3: Inspect the local repository location that we set up via the “settings.xml”.

Maven Local Repository

Step 4: Create a Java “HelloWorld.java” as shown below inside “C:\projects\simple-maven-project\src\main\java\com\mytutorial” where “src\main\java” is the mvn stipulated project structure and “com\mytutorial” is the package.

Step 5: Execute the following command from the project base folder “C:\projects\simple-maven-project”. This basically looks at the “pom.xml” file in that folder.

This would have created a jar file named “simple-maven-project-1.0-SNAPSHOT.jar” inside the “C:\projects\simple-maven-project\target”. This jar file contains the packages & class files. The maven default plugins have compiled the “.java” files and packaged it up as a jar file. This is the basic power of a build tool. It can do a lot more.

Step 6: Run “com.mytutorial.HelloWorld”

Much simpler to create Java projects as jar files.


#1. Setting up the Maven environment

Instead of running the “c:\scripts>environment-setup.cmd” in Windows, you could set up the Windows environment variables as demonstrated in setting up Java tutorial.

set M3_HOME


set the path variable

#2. Installing the jar file to local maven repository

Instead of “mvn clean package”, you can install it to the repository in your “c:\tools\home\.m2\repository” folder.

Publish your project artifact(i.e jar file) to the local repository

Next Java Beginner Tutorial: Setting up Eclipse IDE step by step tutorial.


The following two tabs change content below.
Arulkumaran Kumaraswamipillai
Mechanical Engineer to freelance Java developer within 3 years. Freelancing since 2003 for the major banks, telecoms, retail & government organizations. Attended 150+ Java job interviews, and most often got 3-6 job offers to choose from. Published Java/JEE books via Amazon.com in 2005, and sold 35K+ copies. Books are outdated and replaced with this online Java training. Join my LinkedIn group. 1,350+ paid memberships.

4 comments on “03. ♥ Setting up Maven step by step tutorial
  1. anjaneyareddym says:

    Hi Arul,

    After removing the profile in setting.xml.archetype command is executed. Thanks.


  2. Arulkumaran says:

    1. Check your settings.xml file to ensure that your proxies and repositories are set up correctly. If you are behind a fire wall, you need to set up the proxy. The following is a dummy example. You need to fill in the correct proxy details.

    2. See if you can reach http://search.maven.org/ which is the maven repository. In the search box enter “org/apache/maven/plugins”. You should see “maven-archetype-plugin”.

    3. run your maven command with -X switch as it will give you more debugging statements as to where it is trying to download the plugin from.

  3. anjaneyareddym says:

    I did the same setting as above,But am getting below error.
    ownloading: http://search.maven.org/org/codehaus/mojo/maven-metadata.xml
    INFO] ————————————————————————
    INFO] ————————————————————————
    INFO] Total time: 1.012s
    INFO] Finished at: Tue Mar 17 23:14:40 IST 2015
    INFO] Final Memory: 5M/15M
    INFO] ————————————————————————
    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 repositories [local (c:\tools\home\.m2\repository), cen
    ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    ERROR] Re-run Maven using the -X switch to enable full debug logging.
    ERROR] For more information about the errors and possible solutions, please read the following articles:
    ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException

    Please help on this

By topics – 800+ Q&As ♥ Free ♦ FAQ

open all | close all

Java 200+ FAQs – Quick Brushup

open all | close all

100+ Java Tutorials step by step

open all | close all

13+ Tech Key Areas to standout

open all | close all

Java coding exercises

open all | close all