目录结构
src(源代码)
-main
-java
-package(自定义包)
-test
-java
-package
resources(资源文件)
mvn-v 查看版本
compile 编译
test 测试
package 打包
clean 删除target
install 安装jar包到本地仓库中
archetype插件用于创建符合maven规定的目录骨架
创建目录的两种方式
- mvn archetype:generate
- mvn archetype:generate -DgroupId=组织名,公司网站反写+项目名 -DartifactId=项目名-模块名 -Dversion=版本号 -Dpackage=代码所存在的包名
坐标:构件的唯一标识
仓库:本地仓库,远程仓库
完整的项目构建过程:
清理、编译、测试、打包、集成测试、验证、部署
Maven生命周期
Clean清理项目
Pre-clean执行清理前的工作
Clean清理上一次构建生成的所有文件
Post-clean执行清理后的文件
Default构建项目(核心)
Site生成项目站点
pre-site在生成项目站点前完成的工作
site生成项目站点文档
post-site
site-deploy发布生成站点到服务器上
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/xsd/maven-4.0.0.xsd"> <!-- 指定当前pom版本 --> <modelVersion>4.0.0</modelVersion> <!--主项目标识,定义maven属于哪一个实际项目 --> <groupId>com.zhu.qwe</groupId><!--反写公司网致+项目名 --> <!-- 实际项目一个模块 --> <artifactId>qwe</artifactId><!--项目名+模块名 --> <!--大版本,分支版,小版 SNAPSHOT快照 alpha内测 beta公测 release稳定 GA正式发布 --> <version>0.0.1-SNAPSHOT</version> <!-- 打包方式--> <packaging>jar</packaging> <!-- 项目描述名--> <name>qwe</name> <!-- 地址 --> <url>http://maven.apache.org</url> <!-- 项目描述 --> <description></description> <!-- 开发人员列表--> <developers></developers> <!-- 许可证--> <licenses></licenses> <!-- 组织信息 --> <organization></organization> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <!-- 依赖列表--> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <type></type> <!-- 依赖范围 6种--> <scope>test</scope> <!-- 设置依赖是否可选 --> <optional>true</optional> <!-- 排除依赖传递列表 --> <exclusions> <exclusion> </exclusion> </exclusions> </dependency> </dependencies> <!-- 依赖管理,不会引用到依赖中,类似抽象 --> <dependencyManagement> <dependencies> <dependency> </dependency> </dependencies> </dependencyManagement> <!-- 继承 --> <parent></parent> <!--聚合模块 --> <modules> <module></module> </modules> <!-- 为构建提供支持 --> <build> <!-- 插件列表 --> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.4</version> <executions> <execution> <phase>package</phase> <goals><goal>jar-no-fork</goal></goals> </execution> </executions> </plugin> </plugins> </build> </project>
|
依赖版本冲突
短路优先
- 》b--》c—》x
A--》d—》—》x
路径相同谁先声明,谁优先