Win10安装Maven并更换阿里源
Win10安裝Maven并更換阿里源
文章目錄
- Win10安裝Maven并更換阿里源
- 前言
- 安裝Maven
- 配置環境變量
- 更換Maven源
- 參考文章
前言
根據百度百科的描述,Maven 是基于項目對象模型(POM project object model),可以通過一小段描述信息(配置)來管理項目的構建,報告和文檔的軟件項目管理工具。
Maven的核心功能就是管理項目之間的依賴關系。使用 Java 做過 Web 項目的人都知道,我們使用 Maven 構建項目后,可以在項目中通過 pom.xml 文件的配置來獲取 jar 包,而不是通過手動去添加。
Maven 中一共有三個倉庫:
- 本地倉庫,Maven會將工程中依賴的構件(Jar包)從遠程下載到本機一個目錄下管理,默認的本地倉庫在 C:\Users\用戶名\.m2\repository 目錄下
- 私服,又稱為第三方倉庫,內部中心倉庫。一般是由公司自己設立的,只為本公司內部共享使用。它既可以作為公司內部構件協作和存檔;也可作為公用類庫鏡像緩存,減少在外部訪問和下載的頻率,使用私服為了減少對中央倉庫的訪問。
- 中央倉庫是 Maven 內置的遠程公共倉庫,由 Maven 官方自己維護,里面有大量的常用類庫,并包含了世界上大部分流行的開源項目構件。目前是以 java 為主。
添加 Jar 包的過程:
安裝Maven
安裝 Maven 的過程很簡單,直接去 Apache Maven 官方主頁下載安裝包安裝即可。
Apache Maven 官方主頁的網址是:https://maven.apache.org/
當然我們也可以直接通過百度搜索“maven”,找到 Apache Maven 官方的頁面,點擊進入。
進入官方頁面后,點擊左側導航欄的 Download 標簽,進入下載頁面。
進入下載頁面后往下拉,找到對應的下載鏈接。可以看到當前官方給出的下載版本是 maven-3.6.3 。我們是在 Windows 下安裝 Maven,下載二進制壓縮存檔(zip)即可。
可以看到,其實這個 zip 包并不大,整體還不到 10M,很快就可以下載完成了。
下載完成后,我們選擇在自己喜歡的位置解壓安裝即可。
配置環境變量
Maven 和 JDK 一樣,安裝完成之后,還需要配置環境變量。
我們在電腦桌面上找到“此電腦”圖標,鼠標右擊,選擇“屬性”
點擊“高級系統設置”->“環境變量”->“新建”
新建一個 MAVEN_HOME 環境變量,路徑就是剛才 Maven 安裝的路徑的 bin 目錄
接著,在系統變量中找到 path 變量并選中,點擊“編輯”
在新的彈窗中點擊“新建”,輸入 %MAVEN_HOME% ,點擊確定,對剛才打開的幾個彈窗依次點擊“確定”。
到這一步,Maven 就已經配置完成了,我們可以通過命令行檢測一下。
打開 cmd,輸入 mvn -v 命令,命令行中正常顯示 Maven 的版本信息,則證明配置成功。
更換Maven源
我們之前提到了,Maven 獲取 Jar 包時會到私服或中央倉庫中去查找。
然后 Maven 官方維護的中央倉庫地址在國外,下載速度極其緩慢,十分影響用戶體驗。目前國內用的最多的方法是使用阿里的鏡像 maven 源,速度會快上很多。
我們找到剛才 maven 解壓的目錄,進入 conf 文件夾,找到 setting.xml 文件,使用記事本打開,刪除掉里面所有的內容,將以下內容填入。
<?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 athttp://www.apache.org/licenses/LICENSE-2.0Unless 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 provides configuration for a single user,| and is normally provided in ${user.home}/.m2/settings.xml.|| NOTE: This location can be overridden with the CLI option:|| -s /path/to/user/settings.xml|| 2. Global Level. This settings.xml file provides configuration for all Maven| users on a machine (assuming they're all using the same Maven| installation). It's normally provided in| ${maven.conf}/settings.xml.|| NOTE: This location can be overridden with the CLI option:|| -gs /path/to/global/settings.xml|| The sections in this sample file are intended to give you a running start at| getting the most out of your Maven installation. Where appropriate, the default| values (values used when the setting is not specified) are provided.||--> <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"><mirrors><mirror><id>nexus-aliyun</id><mirrorOf>central</mirrorOf><name>Nexus aliyun</name><url>http://maven.aliyun.com/nexus/content/groups/public</url></mirror> </mirrors> </settings>其中,mirrorOf 標簽中寫 central 的意思是,會從阿里云的中央倉庫進行下載。
更換了阿里的 Maven 源之后,絕大部分的依賴都能輕松下載,好用到飛起。
然而,有一些框架中存在自定義 Jar 包,比如 JEECG,只能從 JEECG 的私服下載依賴,在阿里云倉庫下載可能會存在失敗的情況。
這種情況我們直接修改 mirrorOf 標簽,添加 JEECG 私服,這樣依賴包就可以從 JEECG 私服下載了。
<mirrors><mirror><id>nexus-aliyun</id><mirrorOf>*,!jeecg,!jeecg-snapshots</mirrorOf><name>Nexus aliyun</name><url>http://maven.aliyun.com/nexus/content/groups/public</url></mirror> </mirrors>參考文章
maven(一) maven到底是個啥玩意~
后端環境jdk、maven安裝
Maven私服設置
總結
以上是生活随笔為你收集整理的Win10安装Maven并更换阿里源的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Win10安装Vue-cli
- 下一篇: 五、一元多项式相加