Maven 的相关配置【源码下载、镜像源修改】

本文介绍了如何配置Maven以快速下载源码和JavaDoc,包括切换到阿里云国内镜像源,以及自定义本地仓库路径,确保跨平台开发的无缝对接。
摘要由CSDN通过智能技术生成

PS:网上相关配置很多,这里仅做自己的一个配置在线备份,所以比较简略。

1. Maven 配置下载源码 和 JavaDoc

开发中,经常需要查看某个不太熟悉的类的源码,甚至是该类的 DOC 文档,在 maven 的配置文件(setting.xml)中,加入以下配置,便可以在 IDE 工具中下载选定类的源码。

<activeProfiles>  
    <activeProfile>downloadSources</activeProfile>  
</activeProfiles> 
<profiles>
 <profile>  
     <id>downloadSources</id>  
     <properties>  
         <downloadSources>true</downloadSources>  
         <downloadJavadocs>true</downloadJavadocs>             
     </properties>  
 </profile>
</profiles>

2. 配置国内源【阿里】

官方的默认的源在国外,下载起来太慢,而且一旦有时候下载中断,则很可能要去手动删除中断的包,这样才不会后续出错。所以直接可以把源更换为国内源。

  <mirrors>
	<mirror>
		<id>aliyunmaven</id>
		<mirrorOf>*</mirrorOf>
		<name>阿里云公共仓库</name>
		<url>https://maven.aliyun.com/repository/public</url>
	</mirror>
  </mirrors>

3. 配置本地路径

这里配置的是本地仓库路径,默认情况下你不配置是在用户目录下  ~/.m2/repository 中,由于我为了保证 Linux 和  windows 共用本地仓库,所以这里我把   localRepository 放在了 window 磁盘---“开发工具”,并在 Linux 启动时自动挂载。

 <localRepository>/media/fknight/开发工具/maven/maven-repository</localRepository>

4. 下面是一个我配置好的 setting.xml 文件

用户只需修改本地仓库路径为你自己的实际路径(参考3)就好。

<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值