Saturday Jul 09

Google +1 Button

Maven installation and configuration for Windows

PDF Print E-mail
Monday, 28 March 2011 13:37

Apache Maven Logo Maven 3.0.3 setup instructions

This document describes how to install and setup Maven step by step.

Requirement

Java JDK 1.5 or above (this is to execute Maven - it still allows you to build against 1.3 and prior JDK's)
Memory No minimum requirement

Get the binary

The latest version can be found at http://maven.apache.org/download.html . The downloaded install archive contains everything required to run Maven on your system.

Maven 3.0.3 (Binary zip) apache-maven-3.0.3-bin.zip


Unpack

You can now unpack the install archive. It is recommended to install it in a folder without spaces, quotes and special characters in it. I recommend short name like :

Extract your zip file in <Drive Letter>:\opt. You will get the following directory :

<Drive Letter>:\opt\apache-maven-3.0.3\

If you love like me the power of the symbolic links you can use the following command on Windows Vista or 7 (Run a Dos prompt as Administrator)

Symbolic link to maven installation folder

mklink /D c:\opt\maven c:\opt\apache-maven-3.0.3 

You have know a clean installation.

<Drive Letter>:\opt\maven\

Using symbolic you can perform an upgrade by updating the symbolic link.

You should have the following structure in the folder :

Maven installation directory structure

.
|-- bin
|-- boot
|-- conf
`-- lib

Define the environment variables settings

Maven environment variables settings

Variable Name Value
M2_HOME c:\opt\maven

f you don't have the JAVA_HOME variable defined create one with the location of your JDK

Variable Name Value
JAVA_HOME e.g : C:\opt\Java\jdk1.6.0_23

Add the Maven /bin directory to your PATH variable using the variable M2_HOME

System variable Maven Path definition

Define local repository

The location of your local repository can be changed in your user configuration. The default value is ${user.home}/.m2/repository/ . I strongly recommend to change this location due to the fact that your home is presumably backed up or will be and the size of your home folder can be restricted by the system administrator.

We will change that location in the settings.xml file located in our maven installation folder. The file should be located in :

Maven setup settings.xml file

<Drive Letter>:\opt\apache-maven-3.0.3\conf\settings.xml

Create the following folder

create Maven repostitory folder

mkdir \var\repository

<Drive Letter>:\var\repository

Note: The local repository must be an absolute path.

Content change
Maven installation guide


<settings>
  ...
  <localRepository>C:\var\repository</localRepository>
  ...
</settings>

Configuring proxy

This part is not covered yet¨

Configure Maven to use Nexus (Optional)

Nexus is a maven repository manager. You can use Nexus to host your own maven repository for artifact created in your company, or for caching external artifacts.

If you don't have a nexus server in your organisation you can skip this section.

To use Nexus, you will configure Maven to check Nexus instead of the public repositories. To do this, you'll need to edit your settings.xml file.
Maven installation instruction

<settings>
 ...

  <mirrors>
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://your_nexus_host:nexu_port/nexus/content/groups/public</url>
    </mirror>
  </mirrors>
 ...
<settings>

We have defined a single profile: nexus.

The nexus profile is configured to download from the central repository with a bogus URL of http://central. This URL is overridden by the mirror setting in the same settings.xml file to point to the URL of your single Nexus group. The nexus group is then listed as an active profile in the activeProfiles element.
Maven installation steps

<settings>
  ... 
  <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
  ...
<settings>
 

Maven installation verification

Test your installation

Open a dos prompt and execute

 mvn --version
 

Result

 Apache Moven 3.0.2 (r1056850; 2011-01-09 01:58:10+0100)
 Java version: 1.6.0_23, vendor: Sun Microsystems Inc.
 Java home: C:\opt\Java\jdk1.6.0_23\jre
 Default locale: en_US, platform encoding: Cp1252
 OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows" 


Tips and Tricks

Non modifiable m2_repo variable

If you are facing problem with the m2_repo variable not modifiable in Eclipse (non modifiable m2_repo variable)

You can define a symbolic link in windows to create a link to your settings file in your maven installation folder

mklink "C:\Users\<your login folder name>\.m2\settings.xml" "C:\opt\maven\conf\settings.xml" 

Run a doc command as administrator

Add comment


Security code
Refresh