前言
一直想写一篇关于 Maven 的文章, 但是不知如何下笔, 如果说能使用, 会使用 Maven 的话, 一, 两个小时足矣, 不需要搞懂各种概念. 那么给大家来分享下我是如何理解并使用 maven 的.
什么是 Maven?
Maven 是一个用于项目构建的工具, 通过它便捷的管理项目的生命周期. 即项目的 jar 包依赖, 开发, 测试, 发布打包, 主要管理工作是: 依赖管理, 项目一键构建.
为什么要使用 Maven
使用 maven 构建的项目, 整个项目的体积小
maven 项目不需要手动导入 jar 包, 通过在 pom.xml 中添加依赖, 引用依赖会自动从 maven 仓库下载 jar 包, 方便快捷.
项目一键构建: 使用 maven 可以快速地对项目进行编译 -- 测试 -- 运行 -- 打包 -- 安装
maven 支持跨平台操作, 可在 Windows,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
来源: https://www.cnblogs.com/longronglang/p/11069301.html