Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Apache Maven Cookbook
  • Table Of Contents Toc
  • Feedback & Rating feedback
Apache Maven Cookbook

Apache Maven Cookbook

By : Raghuram Bharathan
4.2 (5)
close
close
Apache Maven Cookbook

Apache Maven Cookbook

4.2 (5)
By: Raghuram Bharathan

Overview of this book

If you are a Java developer or a manager who has experience with Apache Maven and want to extend your knowledge, then this is the ideal book for you. Apache Maven Cookbook is for those who want to learn how Apache Maven can be used for build automation. It is also meant for those familiar with Apache Maven, but want to understand the finer nuances of Maven and solve specific problems.
Table of Contents (13 chapters)
close
close
12
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

Create a Note

Modal Close icon
You need to login to use this feature.
notes
bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Delete Note

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Edit Note

Modal Close icon
Write a note (max 255 characters)
Cancel
Update Note

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY