Maven的包下面的setting.xml文件的初始化配置(全)

首先打开你下载的Maven文件夹下面con文件夹下面的setting.xml文件,这个文件夹特点,除了一些特定的标签基本都是注释的内容,相当于这个文件夹是空的,需要每个用Maven的程序员去配置它,配置的内容一般都是放在这个xml文夹的标签外或标签内。

一般都要做三个配置:

1、本地仓库配置

标签内的就是仓库(放jar包)位置

<!- 选择一个磁盘目录,作为本地仓库 —>

<localRepository>D:\Program Files\maven\myrepository</localRepository>

2 、JDK配置

找到xml文件下标签<profiles>,在标签内添加如下代码,用来限定maven项目默认的jdk版本.

内容如下:

<profiles>


<!--在已有的profiles标签中添加profile标签--><profile>

<id>myjdk</id>

<activation>

<activeByDefault>true</activeByOefault>

<jdk>l.8</jdk>

</activation>

<properties>

<maven.compiler.source>1.8</maven.compiler.source>

<maven.compiler.target>1.8</maven.compiler.target>

<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>

</properties>

</profile>

</profiles>

其次,在标签外需要让标签生效

< !--让增加的profile生效-->
<activeProfiles>

octiveProfile>myjdk</activeProfile>

</activeProfiles>

3、公共仓库【重点】

•除中央仓库之外,还有其他远程仓库。比如aliyun仓库(http://maven.aliyun.CQm/nexus/content/groups/public/) •中央仓库在国外,下载依赖速度过慢,所以都会配置一个国内的公共仓库替代中央仓库。注意:在<mirrors>标签内单独在加一个镜像标签。

<mirrors>

<mirror>

<id>aliyun</id>

<!--中心仓库的mirror(镜像)-->

<mirrorOf>central</mirrorOf>

<name>Nexus aliyun</name>

<!-- aliyun仓库地址 以后所有要指向中心仓库的请求,都会指向aliyun仓库-->

<url>[http://maven.aliyun.com/nexus/content/groups/public>

</mirror>

</mirrors>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Maven 的 `settings.xml` 文件是用来配置 Maven局设置和本地仓库等信息的,它位于 Maven 安装目录下的 `conf` 目录中。 下面是一个简单的 `settings.xml` 文件示例: ```xml <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>/path/to/local/repo</localRepository> <mirrors> <mirror> <id>aliyun</id> <mirrorOf>*</mirrorOf> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> </mirror> </mirrors> <profiles> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <env>dev</env> </properties> <repositories> <repository> <id>central</id> <url>https://repo.maven.apache.org/maven2</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> </profile> <profile> <id>prod</id> <properties> <env>prod</env> </properties> <repositories> <repository> <id>central</id> <url>https://repo.maven.apache.org/maven2</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>dev</activeProfile> </activeProfiles> </settings> ``` 上述示例中,`<localRepository>` 指定了本地 Maven 仓库的路径,`<mirrors>` 配置了阿里云的镜像,`<profiles>` 配置了两个环境的配置信息,`<activeProfiles>` 指定了当前使用的环境。 需要注意的是,`settings.xml` 文件中的配置局生效的,如果有多个项目使用同一份配置文件,那么它们都会受到该文件中的配置影响。如果需要针对某个项目单独配置,可以在项目的 `pom.xml` 文件中添加相应的配置

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值