Preparing to use Maven

In this chapter, it is assumed that you are a first time Maven user and have already set up Maven on your local system. If you have not set up Maven yet, then please refer to Maven’s Download and Installation Instructions before continuing. Depending on where your machine is located, it may be necessary to make a few more preparations for Maven to function correctly. If you are behind a firewall, then you will have to set up Maven to understand that. To do this, create a <user_home>/.m2/settings.xml file with the following content:

<settings>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>proxy.mycompany.com</host>
<port>8080</port>
<username>your-username</username>
<password>your-password</password>
</proxy>
</proxies>
</settings>

If Maven is already in use at your workplace, ask your administrator if there is an internal Maven proxy. If there is an active Maven proxy running, then note the URL and let Maven know you will be using a proxy. Create a <user_home>/.m2/settings.xml file with the following content:

<settings> 
<mirrors>
<mirror>
<id>maven.mycompany.com</id>
<name>My Company's Maven Proxy</name>
<url>http://maven.mycompany.com/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
</settings>

In its optimal mode, Maven requires network access, so for now simply assume that the above settings will work. The settings.xml file will be explained in more detail in the following chapter and you can refer to the Maven Web site for the complete details on the settings.xml file. Now you can perform the following basic check to ensure Maven is working correctly:

mvn -version

If Maven’s version is displayed, then you should be all set to create your first Maven project.