Wednesday 19 March 2014

Maven Environment Variables

In order to make Maven work perfectly, we need to define 2 distinct environment variables. They are M2_HOME and M2_REPO. Let's see the basic difference between the two.

M2_HOME is the variable which defines the Maven installation directory.

M2_REPO is the variable which defines the location of your local repository.

Eg : 

So, for instance, if you installed Maven in /usr/local directory, then M2_HOME should be set to /usr/local/apache-maven-3.x.x

If you want to use some local directory (at any location) as your local repository, the M2_REPO should point to it.

Let's say for example, you created a directory /Users/IronCladZone/Maven/Repos which you intend to use as your local repository, M2_REPO should point to this location.

Also, If you use Eclipse IDE to work on, you should define the same in the preferences as well.

Go to Preferences -> Java -> Build Path -> Classpath Variables and create a New entry for M2_REPO, which points to your local repository and a new entry for M2_HOME which points to Maven installation directory.

Go to Preferences -> Maven -> User Settings and check if the Local Repository is set to the desired location.

Also check if the settings.xml location is rightly pointed. Sometimes, the settings.xml is not located in the ~/.m2/repository location. If not, then it must be located at your M2_HOME/conf location. ( Eg : /usr/local/apache-maven-3.x.x/conf ).

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker