Maven 知识点总结 * man -v 查看maven版本 * compile 编译 * test 编译 * package 打包 * clean 删除target * install 安装jar包到本地仓库
创建目录的两种方式: 1. archetype:generate 按照提示进行选择 2. archetype:generate -DgroupId=组织名,公司网址反写+项目名 -DartifactId=项目名-模块名 -Dversion=版本号 -Dpackage=代码所在包名
坐标(构建) 仓库(本地/远程仓库) 镜像仓库 中央仓库地址:maven 文件/lib/maven-model-builder…jar/org/…./pom-4.0.0.xml文件里
project>
<modelVersion>4.0.0</modelVersion> <repositories> <repository> <id>central</id> <name>Central Repository</name> <url>https://repo.maven.apache.org/maven2</url> <layout>default</layout> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories>镜像仓库(无法访问外网,国内镜像仓库) 打开maven文件/conf/setting.xml 修改为国内China镜像仓库
<mirrors> <!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>maven.net.cn</id> <mirrorOf>central</mirrorOf> <name>central mirror in China</name> <url>http://maven.net.cn/content/groups/public</url> </mirror> —> </mirrors>更改仓库默认路径
打开maven文件/conf/setting.xml
<!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> —> 某路径下新建repo文件夹,将 /path/to/local/repo更改为该路径;复制settings.xml文件,至repo文件夹下。以后每次更新,就不需要重新修改settings.xml文件了。maven生命周期 clean.compile.test.package.install 清理,编译,测试,打包,集成测试,验证,部署 (maven抽象出一套项目的生命周期,而插件是对maven抽象的具体实现) clean 清理项目 1. pre-clean 执行清理前的工作 2. clean 清理上一次构建生成的所有文件 3. post-clean 执行清理后的文件 default 构建项目 1. compile 2. test 3. package 4. install site 生成项目站点 1. pre-site 在生成站点前要完成的工作 2. site 生成项目的站点文档 3. post-site 在生成项目站点后要完成的工作 4. site-depoly 发布生成的站点到服务器上
pom.xml常用标签
<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/maven-v4_0_0.xsd”> <!-- 指定当前pom的版本--> <modelVersion>4.0.0</modelVersion> <groupId>反写公司网址+项目名称</groupId> <artifactId>项目名称+模块名</artifactId> <!— 第一个0表示大版本号,第二个0表示分之版本号,第三0表示小版本号 snapshot 快照 alpha 内部测试 beta 公测 Release 稳定 GA 正式发布 —> <version>0.0.1_NAPSHOT</version> <!— 默认jar (war,zip,pom) —> <package></package> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> </dependency> </dependencies> <name>项目描述名</name> <url>项目地址</url> <description>项目描述</description> <developers>开发人员列表</developers> </project> 依赖范围 <scope></scope> 1. compile 2. provided 3. runtime 4. test 5. system 6. import 依赖传递 ——————————全文完—————————— 2017年2月26日 上午10:15