学习笔记
https://github.com/Tiakon/maven-learning-notes
maven官网
http://maven.apache.org
坐标官网(maven中央仓库)
https://mvnrepository.com/
jar地址
http://repo1.maven.org/maven2/
阿里云镜像
<mirrors>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
超级pom(pom-4.0.0.xml)
在apache-maven-3.6.0\lib下的 maven-model-builder-3.6.0.jar中
<modelVersion>4.0.0</modelVersion> maven的版本
<groupId> 包名
<artifactId> 模块名 项目名
compile 是下载依赖的jar,以及生成target
命令构建目录骨架
maven快速创建项目骨架目录
两种方式:
- mvn archetype:generate 按照提示进行选择
- mvn archetype:generate -DgroupId=com.imooc.maven -DartifactId=
maven-service -Dversion=1.0.0SNAPSHOT -Dpackage=com.imooc.maven.demo- -DgroupId=组织名,公司网址反写+项目名
- -DartifactId=项目名+模块名
- -Dversion=版本号
- -Dpackage=代码所存在的包名
构件坐标:
1. groupId:公司名字+项目名
2. artifactId:项目名+模块名
3. varsion:版本号
仓库:
1. 本地仓库
2. 远程仓库
3. 镜像仓库
报错:No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
依赖范围(Dependency Scope):
compile: 默认的范围,编译测试运行都有效
provided: 在编译和测试时有效, 运行时不加入 如servlet,因为真正运行时容器中有该jar包
runtime: 在测试和运行时有效 例如jdbc驱动的实现
test: 只在测试时有效 如junit
system: 在编译和测试时有效, 与本机系统相关联,可移植性差 例如本机的javahome
import: 导入的范围,只使用在DependencyManagement中,表示从其他的pom中导入dependency的配置
依赖传递和排除依赖:
A依赖B, B依赖C A也会传递依赖C
在A中增加来排除依赖C
<dependency>
<exclusions>
<exclusion>
<groupId>C</groupId>
<artifactId>C</artifactId>
</exclusion>
</exclusions>
</dependency>
maven依赖冲突:
1、短路优先
2、先声明优先
聚合:
<modules>
<module></module>
</modules>
继承:
父POM里面:
<dependencyManagement>
<dependencies>
<dependency>
</dependency>
</dependencies>
</dependencyManagement>
子POM:
<parent>
<groupId></groupId>
</parent>
变量的定义
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit-version>3.8.1</junit-version>
</properties>
变量的引用
<version>${junit-version}</version>
jetty:run 命令 用jetty容器运行
下面是打包成功自动运行