Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Panel
borderStylesolid
titleTable of contents
Table of Contents
minLevel1
maxLevel3
includePagestrue
indent20px
styledisc

Homepage:

http://maven.apache.org/

Download:

http://maven.apache.org/download.html

File(s):

apache-maven-2.1.0-bin.zip (2.9 MB) or apache-maven-2.2.1-bin.tar.gz (2.7 MB)

Installation

Windows:

  • Unzip ZIP-file to an appropriate folder (C:\Program Files): New folder is "apache-maven-2.1.0"

Linux:

  • Unzip tar.gz-package
    Code Block
    titleTerminal
    borderStylesolid
    # cd /usr/local/bin/
    # tar xvfz /home/ralf/DOWNLOADS/apache-maven-2.2.1-bin.tar.gz
    
  • New folder is "/usr/local/bin/apache-maven-2.2.1"

Configuration

  • Add "bin" directory to PATH variable

Windows:

  • Start - Settings - Control Panel - System - Advanced - Environment Variables - System variables
  • "Path" - Edit: (add at the beginning of the line): C:\Program Files\apache-maven-2.1.0\bin;...

Ubuntu:

Code Block
titleTerminal
borderStylesolid
# nano /etc/environment
...
PATH="/usr/local/bin/apache-maven-2.2.1/bin:..."
# source /etc/environment
  • User - create directory .m2 (located at "${user.home}/). Copy the default settings.xml coming with maven to this location:

Windows

Code Block
titleCommand Prompt
borderStylesolid
C:\> mkdir c:\Documents and Settings\<your_username>\.m2
C:\> copy "c:\Program Files\apache-maven-2.1.0\conf\settings.xml" "c:\Documents and Settings\<your_username>\.m2\"
        1 file(s) copied.

Linux:

Code Block
titleTerminal
borderStylesolid
$ cd
$ mkdir .m2
$ cp /usr/local/bin/apache-maven-2.2.1/conf/settings.xml .m2/
  • Maven configuration occurs at 3 levels:
    • Project - most static configuration occurs in pom.xml, should inherit from a company-wide parent pom.xml
    • Installation - this is configuration added once for a Maven installation
    • User - this is configuration specific to a particular user (located at "${user.home}/.m2/settings.xml").

Configuration at a "Global Level" (for all users on a machine) can be done in "${maven.home}/conf/settings.xml"

Local Repository

The location of your local repository can be changed in your user configuration ("${user.home}/.m2/settings.xml").
The default value is "${user.home}/.m2/repository/" (= "~/.m2/repository").

Code Block
titleFile ${user.home}/.m2/settings.xml
borderStylesolid
<settings>
 ...
 <localRepository>C:/Documents and Settings/<your_username>/.m2/repository</localRepository>
 ...
</settings>

Note: The local repository must be an absolute path.

HTTP Proxy

You can configure a proxy to use for some or all of your HTTP requests in Maven 2.0. The username and password are only required if your proxy requires basic authentication (note that later releases may support storing your passwords in a secured keystore - in the mean time, please ensure your settings.xml file (usually ${user.home}/.m2/settings.xml) is secured with permissions appropriate for your operating system).
The nonProxyHosts setting accepts wild cards, and each host not to proxy is separated by the | character. This matches the JDK configuration equivalent.

Code Block
titleFile ${user.home}/.m2/settings.xml
borderStylesolid
<settings>
      ...
      <proxies>
            <proxy>
                  <id>_location name_</id>
                  <active>true</active>
                  <protocol>http</protocol>
                  <host>_internal proxy address_</host>
                  <port>_proxy port_</port>
                  <username>{your_proxyuser}</username>
                  <password>{your_proxypassword}</password>
                  <nonProxyHosts>localhost</nonProxyHosts>
          </proxy>
      </proxies>
      ...
</settings>

Using an intranet mirror repository

Behind the firewall of a company's network it is useful to set up a central repository mirror server (e.g. opensource product "Archiva").

  • Configure this central server in your maven settings file (e.g. "C:\Documents and Settings\<your_username>\.m2\settings.xml"):
Code Block
titleFile ${user.home}/.m2/settings.xml
borderStylesolid
<mirrors>
 ...
 <mirror>
    <id>archiva.central</id>
    <mirrorOf>central</mirrorOf>
    <name>Archiva mirror of central Maven repository.</name>
    <url>http://_server_address_and_port_/archiva/repository/internal/</url>
 </mirror>
 ...
</mirrors>
  • Remove the configuration sections for local repository and for the http proxy to be sure that only the intranet maven mirror is used!
  • To assure that all dependencies are in the proxy repository, clean your local repository (.m2/repository) and choose "Update Dependencies" in the maven plugin for your project.

Test

Windows:

  • Open a new command prompt window
Code Block
titleCommand Prompt
borderStylesolid
C:\>mvn
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO]
 
You must specify at least one goal or lifecycle phase to perform build steps.
The following list illustrates some commonly used build commands:
 
 mvn clean
    Deletes any build output (e.g. class files or JARs).
 mvn test
    Runs the unit tests for the project.
 mvn install
    Copies the project artifacts into your local repository.
 mvn deploy
    Copies the project artifacts into the remote repository.
 mvn site
    Creates project documentation (e.g. reports or Javadoc).
 
Please see
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
for a complete description of available lifecycle phases.
 
Use "mvn --help" to show general usage information about Maven's command line.
 
 
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Wed May 06 12:37:24 CEST 2009
[INFO] Final Memory: 1M/4M
[INFO] ------------------------------------------------------------------------
C:\>

The output is the same under Linux:

Code Block
titleTerminal
borderStylesolid
$ mvn
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
...

This behaviour is ok, because maven does not find a pom.xml file to process and you didn't specify a goal.

Windows:

Code Block
titleCommand Prompt
borderStylesolid
C:\>mvn -version
Apache Maven 2.1.0 (r755702; 2009-03-18 20:10:27+0100)
Java version: 1.6.0_13
Java home: C:\Program Files\Java\jdk1.6.0_13\jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows xp" version: "5.1" arch: "x86" Family: "windows"
C:\>

The platform encoding is not "UTF-8". TODO ??? (set to UTF-8)

Linux:

Code Block
titleCommand Prompt
borderStylesolid
$ mvn -version
Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)
Java version: 1.6.0_16
Java home: /usr/lib/jvm/java-6-sun-1.6.0.16/jre
Default locale: de_DE, platform encoding: UTF-8
OS name: "linux" version: "2.6.28-15-generic" arch: "i386" Family: "unix"

Documentation