maven3安裝與配置


一、Maven簡介

  Maven項目對象模型(POM),可以通過一小段描述信息來管理項目的構建,報告和文檔的項目管理工具軟件。

 

二、Maven下載

1.官網:http://maven.apache.org/download.cgi

2.下載壓縮包

3.解壓到D盤(非系統盤)

 

三、Maven配置(系統必須先安裝JDK)

1.在系統環境變量中新建變量MAVEN_HOME,變量值為maven解壓路徑,如:D:\maven\apache-maven-3.6.3

 

2.在Path變量中,增加%MAVEN_HOME%\bin

 

3.cmd命令行輸入mvn -version出現版本信息即為安裝成功。

 

四、Maven優化

1.將倉庫移到D盤(非系盤)

找到配置setting文件,修改即可:

<localRepository>D:\maven\repository</localRepository>

 

2.將本地鏡像換成阿里鏡像(提速)

由於本地鏡像訪問海外服務器,速度較慢,換成國內鏡像速度大大提升。修改setting.xml的<mirrors>

 

setting.xml

<mirrors>
        <mirror>
            <id>alimaven</id>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <releases>
            <enabled>true</enabled>
            </releases>
            <snapshots>
            <enabled>false</enabled>
            </snapshots>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <mirror>
            <id>aliyunmaven</id>
            <name>阿里雲公共倉庫</name>
            <mirrorOf>*</mirrorOf>        
            <url>https://maven.aliyun.com/repository/public</url>
        </mirror>    
          <!-- mvnrepository鏡像,常用的maven中央倉庫jar查詢站點,可直接當maven鏡像使用 -->  
        <mirror>  
            <id>mvnrepository</id>  
            <mirrorOf>mvnrepository</mirrorOf>  
            <url>http://mvnrepository.com/</url>  
        </mirror>  
        <mirror>  
            <id>ui</id>  
            <mirrorOf>central</mirrorOf>  
            <name>Human Readable Name for this Mirror.</name>  
            <url>http://uk.maven.org/maven2/</url>  
        </mirror>        
        <mirror>  
            <id>jboss-public-repository-group</id>  
            <mirrorOf>central</mirrorOf>  
            <name>JBoss Public Repository Group</name>
            <url>http://repository.jboss.org/nexus/content/groups/public</url>  
        </mirror>    
    </mirrors>

 

注:本人的setting.xml文件:

<?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"> 
<!--需要改成自己的maven的本地倉庫地址-->
    <localRepository>D:\maven\repository</localRepository>
    <servers>
        <server>
           <id>tomcat7</id>
           <username>tomcat</username>
           <password>tomcat</password>
        </server>
    </servers> 
    <mirrors>
        <mirror>
            <id>alimaven</id>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <releases>
            <enabled>true</enabled>
            </releases>
            <snapshots>
            <enabled>false</enabled>
            </snapshots>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <mirror>
            <id>aliyunmaven</id>
            <name>阿里雲公共倉庫</name>
            <mirrorOf>*</mirrorOf>        
            <url>https://maven.aliyun.com/repository/public</url>
        </mirror>    
          <!-- mvnrepository鏡像,常用的maven中央倉庫jar查詢站點,可直接當maven鏡像使用 -->  
        <mirror>  
            <id>mvnrepository</id>  
            <mirrorOf>mvnrepository</mirrorOf>  
            <url>http://mvnrepository.com/</url>  
        </mirror>  
        <mirror>  
            <id>ui</id>  
            <mirrorOf>central</mirrorOf>  
            <name>Human Readable Name for this Mirror.</name>  
            <url>http://uk.maven.org/maven2/</url>  
        </mirror>        
        <mirror>  
            <id>jboss-public-repository-group</id>  
            <mirrorOf>central</mirrorOf>  
            <name>JBoss Public Repository Group</name>
            <url>http://repository.jboss.org/nexus/content/groups/public</url>  
        </mirror>    
    </mirrors>
    <profiles>
        <profile>
            <id>jdk-13</id>  
     <activation>  
         <activeByDefault>true</activeByDefault>  
         <jdk>13</jdk>  
     </activation>
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <maven.compiler.source>13</maven.compiler.source>  
         <maven.compiler.target>13</maven.compiler.target> 
         <maven.compiler.compilerVersion>13</maven.compiler.compilerVersion> 
            </properties>
            <repositories>  
                <repository>  
                    <id>nexus</id>  
                    <name>local private nexus</name>
                    <url>http://maven.oschina.net/content/groups/public/</url>
                </repository>  
            </repositories>  
            <pluginRepositories>  
                <pluginRepository>    
                   <id>nexus</id>
                   <name>local private nexus</name>
                   <url>http://maven.oschina.net/content/groups/public/</url>    
                   <releases>    
                       <enabled>false</enabled>    
                   </releases>    
                   <snapshots>    
                       <enabled>true</enabled>    
                   </snapshots>    
                </pluginRepository>  
            </pluginRepositories> 
        </profile>
    </profiles>     
</settings>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM