官网:https://maven.apache.org/index.html
POM 参考文档: https://maven.apache.org/pom.html
Settings 参考文档: https://maven.apache.org/settings.htmlhtml
Maven 是一个用于构建/管理任何基于Java项目的工具,其自己也是基于Java的 所以须要Java环境。其最初是为了简化 Jakarta Turbine 项目的构建而生。java
其主要处理如下关心的领域:web
mvn archetype:generate "-DgroupId=com.mycompany.app" "-DartifactId=my-app" "-DarchetypeArtifactId=maven-archetype-quickstart" "-DarchetypeVersion=1.4" "-DinteractiveMode=false"
<properties> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> </properties>
cd maven-sample mvn package //mvn会自动下载打包所需组件
java -cp .\target\maven-sample-1.0-SNAPSHOT.jar top.simpleito.demo.App
https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
注:apache
maven-project ├───pom.xml 项目描述文件,定义在生命周期中所需的依赖和所需模块等等 ├───README.txt 项目说明 ├───NOTICE.txt 项目中使用第三方库的资料 ├───LICENSE.txt 许可文件 └───src 包含构建项目所需全部资料,site等等 ├───main 最重要的目录,全部工件(artifect)都应出如今这里 │ ├───java 工件Java源码 │ ├───resources 配置及资源等文件 │ ├───filters 包含在构建阶段将值注入到resources目录下配置属性的文件 │ └───webapp 对于web应用,包含诸如JS/CSS/HTML等资源文件 ├───test 全部测试代码及资源 │ ├───java │ ├───resources │ └───filters ├───it 一般是用于 Maven Failsafe Plugin 的集成测试 ├───site 使用 Maven Site Plugin(https://maven.apache.org/plugins/maven-site-plugin/index.html) 建立的site文档 └───assembly 二进制打包装配配置,通常也不经常使用适用 Apache Maven Assembly Plugin └───target 用于容纳 build 的全部输出
https://maven.apache.org/guides/introduction/introduction-to-the-pom.html
POM 是 Maven 中的基本工做单元,它是一个 XML 文件,包含了"项目有关信息"和"配置Maven构建项目的细节"。
当执行一个任务时,Maven 会在当前目录寻找 POM 文件,从而读取所需的配置信息。
POM 中能够指定许多信息,包括:app
需注意的是:POM 中的<groupid>:<artifactId>:<version>
构成了该工件的彻底限定名
关于 POM、Super POM、最小POM等更多信息参考:Maven POM 详解框架
https://maven.apache.org/settings.html
settings.xml 包含对 Maven 自身的配置,不该绑定到任何特定项目分发给用户。主要包含:本地储存库,代理,身份验证信息等等。webapp
该配置文件可能存在两个位置:maven
若都存在,则内容将被合并做用。优先级:用户级 > 全局
配置详情参考:Maven Settingside
https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
Maven 基于生命周期的概念,意味着构建(build)和分发(distributing)特定工件的过程得以清晰定义,意味着只需学习一小组命令,便可构建任何 Maven 项目。工具
有三种内置构建生命周期(build lifecycle):默认(default)、清理(clean)、site
需注意:
以 default 声明周期为例,主要包含如下 phase:完整的请参考 Lifecycle Reference
附/参考:
- 常见问题/需求QA: https://maven.apache.org/guides/getting-started/index.html#sections
- Maven 官方入门指南: https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
- Baeldung 关于 Standard Directory Layout 介绍文章(Maven官方介绍很差看): https://www.baeldung.com/maven-directory-structure
关于Archetype更多可参考文档,但不太经常使用: https://maven.apache.org/archetype/maven-archetype-plugin/index.html