maven基础之setting.xml常用配置

什么是settings.xml

settings.xml 是maven本地工作的一个全局性的配置文件

位置

如果本地有配置的话,在配置目录的/conf/settings.xml
如果本地没有配置,一般ide或者mvn命令会自动的寻找当前用户的/.m2/setting.xml。
如果这个文件也没有的话 maven会自动加载一个白板配置文件,相当于什么都没有配
建议:小编喜欢在./m2/setting.xml覆盖一个本地的配置文件,而不是配置在配置目录。
这样在切换ide工作空间或者maven命令时都会读取同一个默认配置,不会导致出现各种因为配置文件没有加载而导致的各种问题

配置

说明 这里只列举一些常用的配置,并不是全部的配置
<?xml version="1.0" encoding="UTF-8"?>

<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> 本地仓库目录 默认在当前用户的/.m2/repository文件夹下</localRepository>


  <proxies>
    <!-- proxy
        代理服务器 有些公司是不允许员工直连外网的,需要代理服务器才行,
        但是公司一般都会配私服,所以这个配置一般也不会用。这里只列举一下
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>


  <servers>
    <!-- server 两种私服服务器配置,一般都用账户密码。大公司才会用密钥吧  
    注意这里的id必须和pom里面的仓库id一致,否则发布代码到私服会报401错误
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>


  <mirrors>
    <!-- 
       仓库镜像地址 这里是阿里仓库的镜像地址。
       一般人用的话有个镜像地址可以不用每次都要国外的中央仓库找,不仅网速更好,查找资料的速度也更快。
       如果是公司的话也可以配自己公司的,但是公司的项目建议这个配置在pom里面
    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
 <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>        
    </mirror>
     -->
  </mirrors>
</settings>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要修改 Maven 的 `settings.xml` 文件以配置常用的源地址,您可以按照以下步骤进行操作: 1. 打开 Maven 的安装目录,在其中找到 `conf` 文件夹。 2. 在 `conf` 文件夹中,找到名为 `settings.xml` 的文件。这是 Maven 的全局设置文件。 3. 使用文本编辑器打开 `settings.xml` 文件。 4. 在 `<mirrors>` 元素中,您可以配置常用的源地址。每个源地址都需要添加一个 `<mirror>` 元素。例如,以下是一些常见的源地址配置: ```xml <mirrors> <mirror> <id>aliyun</id> <name>Aliyun Mirror</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>huawei</id> <name>Huawei Mirror</name> <url>https://mirrors.huaweicloud.com/repository/maven/</url> <mirrorOf>central</mirrorOf> </mirror> <!-- 添加更多的 mirror 元素来配置其他源地址 --> </mirrors> ``` 5. 您还可以在 `<profiles>` 元素中配置个别项目的特定源地址。每个项目都可以有一个 `<profile>` 元素。例如: ```xml <profiles> <profile> <id>myproject</id> <activation> <activeByDefault>true</activeByDefault> </activation> <repositories> <repository> <id>central</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> </profile> <!-- 添加更多的 profile 元素来配置其他项目的源地址 --> </profiles> ``` 6. 保存并关闭 `settings.xml` 文件。 现在,您已经成功修改了 Maven 的 `settings.xml` 文件,配置常用的源地址。Maven 在构建项目时将使用这些源地址来下载依赖项。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值