Even Maven to be installed on a partition different from the system one, by default the Mavel local repository is expected to be on the system partition:
If we want to change the local repository location, to be on a partition other than the system one for example, the only what is needed is to be changed the Maven configuration file – settings.xml, located in the Maven installation directory. For the purpose, uncomment the tagg localRepository and add the path to the new directory, which will be used for new local repository:
<settings> ... <localrepository>/path/to/local/repo/</localrepository> ... </settings>
In my case, the change looks in the following way:
<settings> ... <localrepository>D:/config/maven/.m2/repository</localrepository> ... </settings>
By default Eclipse uses its own Maven instance. For local Maven repository, it uses the following folders:
If we install Maven in a location different from the one by default and we configure the local repository to be on a directory different by the one indicated by default, what we could expect is the installation of the generated by Maven archives (jar, war, etc.) in the local repository, to be placed on the newly defined place.
If we don’t reflect these changes in Eclipse, it will use its own Maven installation and its own configuration for the local Maven repository. Respectively, if Eclipse does not find the folder.m2/repository in the current user’s directory (user.home) usually on the system partition/hard-disk, Eclipse creates that folder and install the generated archives for the built Maven projects in it. Thus, the building and installtion (in the terms of Maven) of the same projects from the command line and Eclipse will cause the creation of archives on two different locations.
Moreover, not always the Maven version, which Eclipse uses (M3 in the case of Eclipse 3.6.1 for example) coincide with the one, which is used for the current project (M2 for the project, which I am working on at the moment). As we know, because of the improvements of Maven in version M3 with regards to the optimisation of its performance, the Maven projects, built with this version are incompatible with M2 and vice versa.
So, we can isolate the following problems when we change the local Maven repository and installation, but not reflecting this change in Eclipse:
In order to avoid all these drawbacks, is required to apply two changes to the Eclipse default configuration. Open the menu Window > Preferences and change:
In that way we unify the Maven versions and local repository used via the command line and Eclipse.
]]>
Timothy O'Brien, John Casey, Brian Fox - Maven: The Definitive Guide
Author: Timothy O’Brien, John Casey, Brian Fox
Information in Goodreads: Yes
Available in My Library: Not yet
Raiting: 5/5
Although the book is a bit old (respectively related to an older Maven version) it’s wonderful introduction into Maven ideas and philosophy. Moreover the content is presented in pedagogically consistent manner, which increases additionally the value of the book.
]]>