How to change Maven local repository in eclipse

前端 未结 6 1323
野的像风
野的像风 2020-12-04 14:29

I\'m importing a multiple-module Maven project from the root directory on a shared drive on another server A. On server A, mvn install will run successfully, an

相关标签:
6条回答
  • 2020-12-04 14:41

    location can be specified in Maven->Installation -> Global Settings: settings.xml

    enter image description here

    0 讨论(0)
  • 2020-12-04 14:41

    In newer versions of Eclipse the global configuration file can be set in

    Windows > Preferences > Maven > User Settings > Global Settings

    Don't beat me why global settings can be configured in user settings... Probably because of the same reason why you need to press "Start" to shutdown your PC on Windows... :D

    0 讨论(0)
  • 2020-12-04 14:45

    I found that even after following all the steps above, I was still getting errors saying that my Maven dependencies (i.e. pom.xml) were pointing to jar files that didn't exist.

    Viewing the errors in the Problems tab, for some reason these were still pointing to the old location of my repository. This was probably because I'd changed the location of my Maven repository since creating the workspace and project.

    This can be easily solved by deleting the project from the Eclipse workspace, and re-adding it again through Package Explorer -> R/Click -> Import... -> Existing Projects.

    0 讨论(0)
  • 2020-12-04 14:59

    In general, these answer the question: How to change your user settings file? But the question I wanted answered was how to change my local maven repository location. The answer is that you have to edit settings.xml. If the file does not exist, you have to create it. You set or change the location of the file at Window > Preferences > Maven > User Settings. It's the User Settings entry at

    It's the second file input; the first with information in it.

    If it's not clear, [redacted] should be replaced with the local file path to your .m2 folder.

    If you click the "open file" link, it opens the settings.xml file for editing in Eclipse.

    If you have no settings.xml file yet, the following will set the local repository to the Windows 10 default value for a user named mdfst13:

    <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
                                  https://maven.apache.org/xsd/settings-1.0.0.xsd">
    
      <localRepository>C:\Users\mdfst13\.m2\repository</localRepository>
    </settings>
    

    You should set this to a value appropriate to your system. I haven't tested it, but I suspect that in Linux, the default value would be /home/mdfst13/.m2/repository. And of course, you probably don't want to set it to the default value. If you are reading this, you probably want to set it to some other value. You could just delete it if you wanted the default.

    Credit to this comment by @ejaenv for the name of the element in the settings file: <localRepository>. See Maven — Settings Reference for more information.

    Credit to @Ajinkya's answer for specifying the location of the User Settings value in Eclipse Photon.

    If you already have a settings.xml file, you should merge this into your existing file. I.e. <settings and <localRepository> should only appear once in the file, and you probably want to retain any settings already there. Or to say that another way, edit any existing local repository entry if it exists or just add that line to the file if it doesn't.

    I had to restart Eclipse for it to load data into the new repository. Neither "Update Settings" nor "Reindex" was sufficient.

    0 讨论(0)
  • 2020-12-04 15:00

    In Eclipse Photon navigate to Windows > Preferences > Maven > User Settings > User Setting

    For "User settings" Browse to the settings.xml of the maven. ex. in my case maven it is located on the path C:\Program Files\Apache Software Distribution\apache-maven-3.5.4\conf\Settings.xml

    Depending on the Settings.xml the Local Repository gets automatically configured to the specified location.

    0 讨论(0)
  • 2020-12-04 15:04

    Here is settings.xml --> C:\maven\conf\settings.xml

    0 讨论(0)
提交回复
热议问题