Setting Windows Environment Variables for Maven

   Posted April 10, 2013 by Alex Bahdanovich in Java programming

In order to use Apache Maven for dependency resolution and automatic resolution of transitive dependencies for software projects on a Windows machine, it is necessary to set the proper Windows Environment Variables. This setup is necessary on all modern versions of Windows, and the steps to do so are also similar for all versions.

1.Right-click on the My Computer icon, and choose Properties. This icon may be located on the Windows desktop or the Windows Start menu.

2.In Windows 7, click Advanced system settings in the left side of the System window. In previous versions of Windows, it may be necessary to navigate to the Advanced tab.

3.In the resulting System Properties window, click the Environment Variables button.


4.In the System Variables section of the resulting Environment Variables window that appears, choose the Path variable, and click Edit.

5.In the resulting Edit System Variable window that appears, move the cursor to the end of the Variable value field. Type a semicolon (;), and enter the path to the Maven bin directory (for example, C:\apache-maven-3.0.4\bin). Click OK. It may also be necessary to click OK through the series of menus that led to the Edit System Variable window in order to close them.

6.In order to test that the Path environment variable has been correctly set up, open a Windows command prompt by clicking Start, choosing Run, type CMD and click OK.


7.On the Windows command prompt, type mvn –version and press enter. If the Path environment variable upgrade was successful, then you should be able to see versioning information for Maven.

Now you will be able to compile, build, and test your Maven-enabled project from the Windows command line.

 

About Alex Bahdanovich

Writer, author, wordsmith -- this tech enthusiast enjoys Starbucks, good reads, and golden retrievers.
View more articles by Alex Bahdanovich

The Conversation

Follow the reactions below and share your own thoughts.

  • SSN

    Hi,I’m trying to install maven and have given the following enviroment variables :
    JAVA_HOME::C:\Program Files\Java\jdk1.6.0_43
    MAVEN_HOME::D:\Softwares\apache-maven-3.0.4
    PATH::%PATH%;D:\Softwares\apache-maven-3.0.4\bin
    When I run mvn -version in command prompt I’m getting this:

    C:\Documents and Settings\xyz>mvn -version
    Usage: java [-options] class [args…]
    (to execute a class)
    or java [-options] -jar jarfile [args…]
    (to execute a jar file)

    where options include:
    -client to select the “client” VM
    -server to select the “server” VM
    -hotspot is a synonym for the “client” VM [deprecated]
    The default VM is client.

    -cp
    -classpath
    A ; separated list of directories, JAR archives,
    and ZIP archives to search for class files.
    -D=
    set a system property
    -verbose[:class|gc|jni]
    enable verbose output
    -version print product version and exit
    -version:
    require the specified version to run
    -showversion print product version and continue
    -jre-restrict-search | -jre-no-restrict-search
    include/exclude user private JREs in the version search
    -? -help print this help message
    -X print help on non-standard options
    -ea[:…|:]
    -enableassertions[:…|:]
    enable assertions
    -da[:…|:]
    -disableassertions[:…|:]
    disable assertions
    -esa | -enablesystemassertions
    enable system assertions
    -dsa | -disablesystemassertions
    disable system assertions
    -agentlib:[=]
    load native agent library , e.g. -agentlib:hprof
    see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:[=]
    load native agent library by full pathname
    -javaagent:[=]
    load Java programming language agent, see java.lang.instrument

    -splash:
    show splash screen with specified image

    What am I missing here? Please help!