Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Apache Maven Cookbook

You're reading from   Apache Maven Cookbook Over 90 hands-on recipes to successfully build and automate development life cycle tasks following Maven conventions and best practices

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher Packt
ISBN-13 9781785286124
Length 272 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

Table of Contents (13) Chapters Close

Preface 1. Getting Started 2. IDE Integration with Maven FREE CHAPTER 3. Maven Lifecycle 4. Essential Maven Plugins 5. Dependency Management 6. Code Quality Plugins 7. Reporting and Documentation 8. Handling Typical Build Requirements 9. Multi-module Projects 10. Java Development with Maven 11. Advanced Maven Usage Index

Changing the location of the Maven repository

There are three types of Maven repositories:

  • Local: This is the repository in your computer filesystem
  • Remote: This is the repository from where the required Maven files get downloaded
  • Mirrors: These are repository managers, such as Nexus and Artifactory, that mirror various repositories

You will have seen Maven downloading a number of files (called poms and jars). Let us see where they are located in your computer:

  • Go to your HOME folder (C:\Users\username) in the case of Microsoft Windows, /Users/username for Mac, and, /home/username (or a similar location) for Linux
  • You will notice the .m2 folder and within that, a subfolder called repository

    Tip

    Any folder that starts with a dot (.) is typically hidden from view. You will need to change your folder viewer settings to see it.

  • You will see a number of folders and files that are used by Maven

You may want to change this location for the following reasons:

  • You may want to conserve space in the C drive and store these folders and files in the D drive on Microsoft Windows.
  • You may want to take a back up of the contents. Backup software usually backs up contents in specific folders of the filesystem.
  • Your organization may have a policy for all users to store a local repository in the same folder.

How to do it...

To change the location of the Maven repository, perform the following steps:

  1. Create a file called settings.xml in the .m2 folder.
  2. Add the following contents to the settings.xml file that you just created:
    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                          http://maven.apache.org/xsd/settings-1.0.0.xsd">
        <localRepository>C:/software/maven</localRepository>
    </settings>

    Notice the highlighted part of the preceding code. We have changed the location of the repository contents to C:\software\maven. You can change it to any valid folder name.

  3. Delete the repository subfolder and run the mvn package command again.

    You will now notice that the repository folder is not created in the .m2 folder. Instead, it is created in C:\software\maven.

How it works...

Maven determines the location of the local repository in the following way:

  • If settings.xml exists in the user's .m2 folder, which contains the <localRepository> tag, then Maven uses its contents to determine the location
  • If not, Maven will check if localRepository is explicitly defined in the default settings.xml, present in the conf folder of the Maven installation
  • If it is not present there, Maven will use the default value for the local repository, which is the user's .m2 folder
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image