我是如何理解並使用maven的

Refain發表於2019-06-23

前言

一直想寫一篇關於Maven的文章,但是不知如何下筆,如果說能使用,會使用Maven的話,一、兩個小時足矣,不需要搞懂各種概念。那麼給大家來分享下我是如何理解並使用maven的。

什麼是Maven?

Maven是一個用於專案構建的工具,通過它便捷的管理專案的生命週期。即專案的jar包依賴,開發,測試,釋出打包,主要管理工作是:依賴管理,專案一鍵構建。

為什麼要使用Maven

  • 使用maven構建的專案,整個專案的體積小
  • maven專案不需要手動匯入jar包,通過在pom.xml中新增依賴,引用依賴會自動從maven倉庫下載jar包,方便快捷。
  • 專案一鍵構建:使用maven可以快速地對專案進行編譯--測試--執行--打包--安裝
  • maven支援跨平臺操作,可在window、linux、mac上使用
  • maven遵循規範開發有利於提高大型團隊的開發效率,降低專案的維護成本,屬於主流技術,一般公司都會使用maven來構建專案

maven倉庫的配置

下載專案引用需要jar包的時候存放的本地路徑

倉庫的分類

  • 本地倉庫
  • 私服(公司的倉庫)
  • 中央倉庫

三個倉庫之間的關係

三者之間的關係是,當我們在專案中依賴一個jar包時,Maven程式會先去本地倉庫中找,如果沒找到就回去私服找,如果還是沒有,最後就回去中央倉庫找。其過程如下圖:

本地倉庫的配置

找到已安裝的maven路徑,如:apache-maven-3.3.9\conf 目錄下settings.xml 檔案並用notepad++開啟,ctrl+F找到localRepository標籤,將路徑設定為D:/repository,如下圖:

說明:什麼是本地倉庫? 就是是由個人將常用到的jar包放入一個倉庫中,已備自己在專案中使用,可從別人配置好的jar包倉庫拷到自己本地目錄,因為倉庫一般很大,首次下載需要很長一段時間。

配置私服地址

實際工作中,很多專案都會用到maven私服倉庫,一般公司都有統一的maven私服倉庫,由於公司都是統一化管理,這時候我們就要配置統一的私服倉庫,舉例如下:

<mirrors>
    
    <mirror>
      <!--This is used to direct the public snapshots repo in the 
          profile below over to a different nexus group -->
      <id>nexus-public-snapshots</id>
      <mirrorOf>public-snapshots</mirrorOf>
      <url>http://192.168.1.118:8888/nexus/content/repositories/apache-snapshots/</url>
    </mirror>
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    </mirror>
  </mirrors>

pom檔案說明

pom.xml檔案,一般描述了maven專案的基本資訊,比如groupId,artifactId,version等,一個最簡單的pom.xml檔案至少需要包含四個元素:modelVersion, groupId, artiffactId和version。

比如一個基本的pom.xml檔案如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test</groupId> //當前專案的資訊
    <artifactId>maven-demo</artifactId>
    <version>1.0-SNAPSHOT</version>//SNAPSHOT(快照)表示該專案還在開發中。
</project>

其中主要的標籤含義如下:

project:pom.xml 檔案中的頂層元素;

modelVersion:指明 POM 使用的物件模型的版本。這個值很少改動。

groupId:指明建立專案的組織或者小組的唯一標識。

GroupId 是專案的關鍵標識,典型的,此標識以組織的完全限定名來定義。比如,org.apache.maven.plugins 是所有 Maven 外掛專案指定的 groupId。

artifactId:指明此專案產生的主要產品的基本名稱。專案的主要產品通常為一個 JAR 檔案。第二,象原始碼包通常使用 artifactId 作為最後名稱的一部分。典型的產品名稱使用這個格式:

version:專案產品的版本號。Maven 幫助你管理版本,可以經常看到 SNAPSHOT 這個版本,表明專案處於開發階段。

在專案中新增外掛,以及對外掛的配置

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>//編譯外掛
                <version>2.4.3</version>//外掛的版本號
                <configuration>//對外掛進行配置
                    <source>1.7</source>//原始碼編譯版本
                    <target>1.7</target>//目標平臺編譯版本;
                    <encoding>UTF-8</encoding>//設定外掛或資原始檔的編碼方式。
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>//執行測試用例的外掛
                <version>2.17</version>//外掛的版本號
                <configuration>//對外掛進行配置
                    <suiteXmlFiles>
                        <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>//測試套件執行路徑
                    </suiteXmlFiles>

                </configuration>
            </plugin>
        </plugins>
    </build>

 

如何在pom檔案中新增依賴jar包

實際開發中需要引用jar包後,再進行開發,那麼在pom中新增依賴呢?

1、比如我想新增testng.jar包,那麼可以通過訪問網址 https://mvnrepository.com/ ,然後在搜尋框中輸入testng,回車

2、點選testng,選擇對應版本如6.14.3

3、複製紅框中內容,放到dependencies標籤內。

在pom中引用完成,並自動下載依賴jar包。

  <dependencies>
        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.3</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

 實際效果:

編寫一個測試類

package com.test.demo;

import org.testng.Assert;
import org.testng.annotations.Test;

public class HellowWorld {

    @Test
    public void test() {
        Assert.assertEquals("HellowWorld","HellowWorld");
    }
}

 maven專案的目錄結構

F:\mavendemo>tree
卷 新加捲 的資料夾 PATH 列表
卷序列號為 5C5B-6DDB
F:.
├─.idea
└─src
├─main
│ ├─java
│ │ └─com
│ │ └─test
│ │ └─demo
│ └─resources
└─test
└─java
└─com
└─test
└─demo

注意上面帶紅色的目錄名,maven專案採用“約定優於配置”的原則,src/main/java約定用於存放原始碼,src/main/test用於存放單元測試程式碼,src/target用於存放編譯、打包後的輸出檔案。這是全世界maven專案的通用約定,請記住這些固定的目錄結構。

編譯和測試

在專案根目錄下執行mvn clean compile命令。執行輸出如下所示:

Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-demo 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-demo ---
[INFO] Deleting F:\mavendemo\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ maven-demo ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to F:\mavendemo\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.336 s
[INFO] Finished at: 2019-06-23T17:33:29+08:00
[INFO] Final Memory: 13M/309M
[INFO] ------------------------------------------------------------------------

clean:清理輸出目錄target下生成jar包

compile:編譯專案主程式碼

編譯完成後,我們一般都會執行測試程式碼進行單元測試,雖然很多情況下,我們並沒有這麼做,但是我還是建議大家通過Maven做一些自動化的單元測試。

測試用例編寫完畢之後就可以呼叫Maven執行測試,執行mvn clean test命令,輸出如下:

Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-demo 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-demo ---
[INFO] Deleting F:\mavendemo\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ maven-demo ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to F:\mavendemo\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory F:\mavendemo\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ maven-demo ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to F:\mavendemo\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.17:test (default-test) @ maven-demo ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.032 s
[INFO] Finished at: 2019-06-23T17:27:28+08:00
[INFO] Final Memory: 15M/309M
[INFO] ------------------------------------------------------------------------

打包和執行

打包就是將我們編寫的應用打成JAR包或者WAR包,我們執行mvn clean package命令就可以完成打包。mvn clean package命令的輸出如下:

Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-demo 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-demo ---
[INFO] Deleting F:\mavendemo\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ maven-demo ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to F:\mavendemo\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory F:\mavendemo\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ maven-demo ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to F:\mavendemo\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.17:test (default-test) @ maven-demo ---
[INFO] Surefire report directory: F:\mavendemo\test-output

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.test.demo.TestHellowWorld
Configuring TestNG with: TestNG652Configurator
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.498 sec - in com.test.demo.TestHellowWorld
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ maven-demo ---
[INFO] Building jar: F:\mavendemo\target\maven-demo-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.356 s
[INFO] Finished at: 2019-06-23T17:46:00+08:00
[INFO] Final Memory: 17M/311M
[INFO] ------------------------------------------------------------------------

執行完後,會在target目錄下生成jar包

如果別的專案要引用這個JAR包時,我們將這個JAR包複製到其它專案的classpath中就OK了。

但是這樣拷貝就違背了我們當初想要自動解決依賴的問題,所以如何才能讓其它的Maven專案直接引用這個JAR包呢?我們需要執行mvn clean install命令。

Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-demo 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-demo ---
[INFO] Deleting F:\mavendemo\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ maven-demo ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to F:\mavendemo\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory F:\mavendemo\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ maven-demo ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to F:\mavendemo\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.17:test (default-test) @ maven-demo ---
[INFO] Surefire report directory: F:\mavendemo\test-output

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.test.demo.TestHellowWorld
Configuring TestNG with: TestNG652Configurator
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.611 sec - in com.test.demo.TestHellowWorld
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ maven-demo ---
[INFO] Building jar: F:\mavendemo\target\maven-demo-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ maven-demo ---
[INFO] Installing F:\mavendemo\target\maven-demo-1.0-SNAPSHOT.jar to E:\repository\com\test\maven-demo\1.0-SNAPSHOT\maven-demo-1.0-SNAPSHOT.jar
[INFO] Installing F:\mavendemo\pom.xml to E:\repository\com\test\maven-demo\1.0-SNAPSHOT\maven-demo-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.643 s
[INFO] Finished at: 2019-06-23T20:39:34+08:00
[INFO] Final Memory: 16M/211M
[INFO] ------------------------------------------------------------------------

使用Archetype生成專案骨架

下面通過用命名行建立一個最基本的maven專案

mvn archetype:generate

先建立專案的根目錄,從碟符開始,命令列視窗下輸入

mkdir demotest

cd demotest

mvn archetype:generate

首次執行時,mvn會從遠端"中央倉庫"下載一些必需的檔案到"本地倉庫" -

如果你有興趣,可以在等待下載過程中,觀察一下"C:\Users\當前使用者名稱\.m2\repository"目錄下是不是多了很多檔案。

下載完成後,會自動進入互動模式,會讓你輸入一些基本資訊,類似下面這樣:

F:\demotest>mvn archetype:generate
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.0.0:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.0.0:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:3.0.0:generate (default-cli) @ standalone-pom ---
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-artifact-transfer/0.9.0/maven-artifact-transfer-0.9.0.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-artifact-transfer/0.9.0/maven-artifact-transfer-0.9.0.pom (8 KB at 5.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-common-artifact-filters/3.0.0/maven-common-artifact-filters-3.0.0.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-common-artifact-filters/3.0.0/maven-common-artifact-filters-3.0.0.pom (5 KB at 10.1 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-components/22/maven-shared-components-22.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-components/22/maven-shared-components-22.pom (5 KB at 11.2 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-provider-api/2.8/wagon-provider-api-2.8.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-provider-api/2.8/wagon-provider-api-2.8.pom (2 KB at 3.8 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon/2.8/wagon-2.8.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon/2.8/wagon-2.8.pom (19 KB at 41.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy/1.8.3/groovy-1.8.3.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy/1.8.3/groovy-1.8.3.pom (32 KB at 26.9 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/antlr/antlr/2.7.7/antlr-2.7.7.pom
Downloaded: https://repo.maven.apache.org/maven2/antlr/antlr/2.7.7/antlr-2.7.7.pom (0 B at 0.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/asm/asm/3.2/asm-3.2.pom
Downloaded: https://repo.maven.apache.org/maven2/asm/asm/3.2/asm-3.2.pom (0 B at 0.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/asm/asm-parent/3.2/asm-parent-3.2.pom
Downloaded: https://repo.maven.apache.org/maven2/asm/asm-parent/3.2/asm-parent-3.2.pom (0 B at 0.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/asm/asm-commons/3.2/asm-commons-3.2.pom
Downloaded: https://repo.maven.apache.org/maven2/asm/asm-commons/3.2/asm-commons-3.2.pom (0 B at 0.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/asm/asm-tree/3.2/asm-tree-3.2.pom
Downloaded: https://repo.maven.apache.org/maven2/asm/asm-tree/3.2/asm-tree-3.2.pom (0 B at 0.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/asm/asm-util/3.2/asm-util-3.2.pom
Downloaded: https://repo.maven.apache.org/maven2/asm/asm-util/3.2/asm-util-3.2.pom (0 B at 0.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/asm/asm-analysis/3.2/asm-analysis-3.2.pom
Downloaded: https://repo.maven.apache.org/maven2/asm/asm-analysis/3.2/asm-analysis-3.2.pom (0 B at 0.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-6/plexus-interactivity-api-1.0-alpha-6.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-6/plexus-interactivity-api-1.0-alpha-6.pom (0 B at 0.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-interactivity/1.0-alpha-6/plexus-interactivity-1.0-alpha-6.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-interactivity/1.0-alpha-6/plexus-interactivity-1.0-alpha-6.pom (0 B at 0.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-components/1.1.9/plexus-components-1.1.9.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-components/1.1.9/plexus-components-1.1.9.pom (0 B at 0.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-script-interpreter/1.0/maven-script-interpreter-1.0.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-script-interpreter/1.0/maven-script-interpreter-1.0.pom (4 KB at 8.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/ant/ant/1.8.1/ant-1.8.1.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/ant/ant/1.8.1/ant-1.8.1.pom (0 B at 0.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/ant/ant-parent/1.8.1/ant-parent-1.8.1.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/ant/ant-parent/1.8.1/ant-parent-1.8.1.pom (0 B at 0.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/archetype/archetype-catalog/3.0.0/archetype-catalog-3.0.0.jar
Downloading: https://repo.maven.apache.org/maven2/net/sourceforge/jchardet/jchardet/1.0/jchardet-1.0.jar
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/archetype/archetype-common/3.0.0/archetype-common-3.0.0.jar
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/archetype/archetype-descriptor/3.0.0/archetype-descriptor-3.0.0.jar
Downloading: https://repo.maven.apache.org/maven2/jdom/jdom/1.0/jdom-1.0.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/archetype/archetype-catalog/3.0.0/archetype-catalog-3.0.0.jar (19 KB at 39.7 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy/1.8.3/groovy-1.8.3.jar
Downloaded: https://repo.maven.apache.org/maven2/jdom/jdom/1.0/jdom-1.0.jar (0 B at 0.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/antlr/antlr/2.7.7/antlr-2.7.7.jar
Downloaded: https://repo.maven.apache.org/maven2/antlr/antlr/2.7.7/antlr-2.7.7.jar (0 B at 0.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/asm/asm/3.2/asm-3.2.jar
Downloaded: https://repo.maven.apache.org/maven2/net/sourceforge/jchardet/jchardet/1.0/jchardet-1.0.jar (26 KB at 26.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/asm/asm-commons/3.2/asm-commons-3.2.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/archetype/archetype-descriptor/3.0.0/archetype-descriptor-3.0.0.jar (24 KB at 20.6 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/asm/asm-util/3.2/asm-util-3.2.jar
Downloaded: https://repo.maven.apache.org/maven2/asm/asm-util/3.2/asm-util-3.2.jar (0 B at 0.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/asm/asm-analysis/3.2/asm-analysis-3.2.jar
Downloaded: https://repo.maven.apache.org/maven2/asm/asm-analysis/3.2/asm-analysis-3.2.jar (0 B at 0.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/asm/asm-tree/3.2/asm-tree-3.2.jar
Downloaded: https://repo.maven.apache.org/maven2/asm/asm-commons/3.2/asm-commons-3.2.jar (33 KB at 20.2 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.21/plexus-utils-3.0.21.jar
Downloaded: https://repo.maven.apache.org/maven2/asm/asm-tree/3.2/asm-tree-3.2.jar (22 KB at 10.6 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-6/plexus-interactivity-api-1.0-alpha-6.jar
Downloaded: https://repo.maven.apache.org/maven2/asm/asm/3.2/asm-3.2.jar (43 KB at 19.6 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-invoker/2.2/maven-invoker-2.2.jar
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-6/plexus-interactivity-api-1.0-alpha-6.jar (12 KB at 4.7 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-artifact-transfer/0.9.0/maven-artifact-transfer-0.9.0.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-invoker/2.2/maven-invoker-2.2.jar (30 KB at 8.3 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-common-artifact-filters/3.0.0/maven-common-artifact-filters-3.0.0.jar
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.21/plexus-utils-3.0.21.jar (240 KB at 56.1 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-script-interpreter/1.0/maven-script-interpreter-1.0.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-artifact-transfer/0.9.0/maven-artifact-transfer-0.9.0.jar (121 KB at 27.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/ant/ant/1.8.1/ant-1.8.1.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/ant/ant/1.8.1/ant-1.8.1.jar (0 B at 0.0 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-script-interpreter/1.0/maven-script-interpreter-1.0.jar (21 KB at 4.0 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-common-artifact-filters/3.0.0/maven-common-artifact-filters-3.0.0.jar (56 KB at 10.6 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/archetype/archetype-common/3.0.0/archetype-common-3.0.0.jar (324 KB at 51.1 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy/1.8.3/groovy-1.8.3.jar (5394 KB at 19.0 KB/sec)
[INFO] Generating project in Interactive mode
.............................................................................

執行這個命令後,後看到很多輸出,然後再按照提示一步步操作,一個Maven專案就建立成功了。

總結 

到此,關於maven的入門基礎知識總結完畢,文章知識點相對繁瑣、複雜,還請讀者多次閱讀和實踐,如有錯誤之處,煩請多指正!

參考文章:

https://www.jellythink.com/archives/502

https://www.cnblogs.com/yjmyzz/p/3495762.html

相關文章