maven教程总结完成
1
.vscode/settings.json
vendored
@@ -197,4 +197,5 @@
|
||||
"Java源代码/Lesson05",
|
||||
"Java源代码/Lesson06"
|
||||
],
|
||||
"java.configuration.updateBuildConfiguration": "disabled",
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
## 1 概述
|
||||
> 参考文档 http://heavy_code_industry.gitee.io/code_heavy_industry/pro002-maven/chapter10/verse02.html
|
||||
### 应用场景
|
||||
|
||||

|
||||
@@ -10,7 +11,8 @@
|
||||
|
||||

|
||||
|
||||
nexus私服,企业可以创建内部的公用仓库
|
||||
### nexus私服
|
||||
企业可以创建内部的公用仓库
|
||||
|
||||
* nexus是一个强大的maven仓库管理器,它极大的简化了本地内部仓库的维护和外部仓库的访问.
|
||||
* nexus是一套开箱即用的系统不需要数据库,它使用文件系统加Lucene来组织数据
|
||||
@@ -26,6 +28,10 @@ Maven 是一个项目管理工具,可以对 Java 项目进行构建、依赖
|
||||
|
||||

|
||||
|
||||
* 项目对象模型POM:,xml文件,项目基本信息,描述项目构建过程,声明项目依赖。
|
||||
* 构件:任何一个依赖、插件或者项目构建输出,都可以称之为构件。
|
||||
* 插件Plugin:maven是依赖插件完成任务的,项目管理工具。
|
||||
* 仓库Repository:maven仓库能够帮我们管理构件
|
||||
|
||||
### 基本作用
|
||||
|
||||
@@ -34,7 +40,11 @@ Maven 是一个项目管理工具,可以对 Java 项目进行构建、依赖
|
||||
1. 打java包或者war包
|
||||
3. **统一开发结构**。提供标准的、统一的项目结构。
|
||||
|
||||
## 1 maven相关概念
|
||||
### 基本原理
|
||||
|
||||
|
||||

|
||||
## 2 maven相关概念
|
||||
|
||||
### POM项目对象模型
|
||||
项目对象模型(Project Object Management,POM)是一种模型化思想。与DOM、BOM等文档对象模型、浏览器对象模型类似。POM将工程抽象为一个模型,用程序中的对象来描述这个模型,实现项目的管理。
|
||||
@@ -139,9 +149,48 @@ mvn archetype:generate -DgroupId=com.demo -DartifactId=webproject -DarchetypeArt
|
||||
1. 需要自己指定源代码、测试代码、源代码资源文件和测试资源文件。
|
||||
2. 可以在idea中自动创建启动参数。edit configuration
|
||||
3. 使用原型创建Maven模块。选择不同的Maven原型文件。
|
||||
4. 直接在web中添加tomcat插件,即可在本地展示网站。
|
||||
|
||||
## maven简介
|
||||
|
||||
> 纯java开源项目。**项目管理工具**,对java项目进行构建、依赖管理。也可以用于构建和管理其他项目(c#,Ruby,Scala)
|
||||
|
||||
> 在上一次做handoop mapreduce的时候,发现了pom文件,然后配置了maven,作为maven工程打开过。但是具体的过程,为啥忘得一干二净,只记得自己曾经对maven的setting文件进行修改,那个时候应该还创建了本地库。但是完全记不清了。
|
||||
|
||||
## 4 maven主要功能
|
||||
|
||||
* 项目构建
|
||||
* 依赖管理
|
||||
* 项目管理
|
||||
* 文档生成
|
||||
* 报告
|
||||
* SCMs
|
||||
* 发布
|
||||
* 分发
|
||||
* 邮件列表
|
||||
|
||||
|
||||
### idea创建web项目
|
||||
### maven项目目录结构
|
||||
| 目录| 目的|
|
||||
|-|-|
|
||||
| ${basedir} |存放pom.xml和所有的子目录|
|
||||
| ${basedir}/src/main/java |项目的java源代码|
|
||||
| ${basedir}/src/main/resources |项目的资源,比如说property文件,springmvc.xml|
|
||||
| ${basedir}/src/test/java |项目的测试类,比如说Junit代码|
|
||||
| ${basedir}/src/test/resources |测试用的资源|
|
||||
| ${basedir}/src/main/webapp/WEB-INF |web应用文件目录,web项目的信息,比如存放web.xml、本地图片、jsp视图页面|
|
||||
| ${basedir}/target |打包输出目录|
|
||||
| ${basedir}/target/classes |编译输出目录|
|
||||
| ${basedir}/target/test-classes |测试编译输出目录|
|
||||
| Test.java |Maven只会自动运行符合该命名规则的测试类|
|
||||
| ~/.m2/repository |Maven默认的本地仓库目录位置|
|
||||
|
||||
1. 直接在web中添加tomcat插件,即可在本地展示网站。
|
||||
|
||||
### maven项目的优势
|
||||
* 基于模型的构建 − Maven能够将任意数量的项目构建到预定义的输出类型中,如 JAR,WAR 或基于项目元数据的分发,而不需要在大多数情况下执行任何脚本。
|
||||
* 项目信息的一致性站点 − 使用与构建过程相同的元数据,Maven 能够生成一个网站或PDF,包括您要添加的任何文档,并添加到关于项目开发状态的标准报告中。
|
||||
* 发布管理和发布单独的输出 − Maven 将不需要额外的配置,就可以与源代码管理系统(如 Subversion 或 Git)集成,并可以基于某个标签管理项目的发布。它也可以将其发布到分发位置供其他项目使用。Maven 能够发布单独的输出,如 JAR,包含其他依赖和文档的归档,或者作为源代码发布。
|
||||
* 向后兼容性 − 您可以很轻松的从旧版本 Maven 的多个模块移植到 Maven 3 中。
|
||||
* 子项目使用父项目依赖时,正常情况子项目应该继承父项目依赖,无需使用版本号
|
||||
* 并行构建 − 编译的速度能普遍提高20 - 50 %。
|
||||
* 更好的错误报告 − Maven 改进了错误报告,它为您提供了 Maven wiki 页面的链接,您可以点击链接查看错误的完整描述。
|
||||
@@ -1,19 +1,234 @@
|
||||
## 1 简介
|
||||
|
||||
### POM概念
|
||||
POM( Project Object Model,项目对象模型 ) 是 Maven 工程的基本工作单元,是一个XML文件,包含了项目的基本信息,用于描述项目如何构建,声明项目依赖,等等。
|
||||
|
||||
pom.xml 项目模型对象文件。POM 中可以指定以下配置:
|
||||
|
||||
* 项目依赖
|
||||
* 插件
|
||||
* 执行目标
|
||||
* 插件:执行目标
|
||||
* 项目构建 profile
|
||||
* 项目版本
|
||||
* 项目开发者列表
|
||||
* 相关邮件列表信息
|
||||
|
||||
## 2 POM 标签大全详解
|
||||
|
||||
### pom工程之间的关系
|
||||
* 在dependency中的依赖关系。
|
||||
* 在parent中的继承关系
|
||||
* 在module中的聚合关系
|
||||
|
||||
|
||||
## 2 依赖关系dependency
|
||||
> 依赖的传递主要通过dependency标签实现的
|
||||
|
||||
### scope依赖范围标签
|
||||
scope的取值用来定义依赖生效的空间(main目录、test目录)和时间(开发中、部署中)。
|
||||
|
||||
标签位置 dependencies/dependency/scope
|
||||
标签取值 compile/test/provided/system/runtime/import
|
||||
|
||||
* compile是最基本的标签,在所有的范围、所有的时间都能生效。
|
||||
* test标签,仅仅在test目录开发阶段生效的依赖,生效空间和时间范围最小。
|
||||
* prvoide标签,在开发阶段生效,在部署阶段不生效的依赖(因为部署环境提供了该依赖,不需要打包到jar或者war包中)
|
||||
* import maven也是单继承。通过import导入多个依赖。导入的依赖必须是POM工程,package中的打包方式是pom
|
||||

|
||||
* system 强行将当前系统下的jar包作为依赖导入进来。使用系统根路径,可以是相对路径。
|
||||

|
||||
* runtime编译时不需要,但是运行时需要的jar。实际运行时需要接口的实现类。JDBC接口标准提供了一系列借口,能够进行编译。但是运行时需要JDBC的具体实现。
|
||||

|
||||
|
||||
### optional可选依赖
|
||||
|
||||
在开发阶段需要的类,但是在运行阶段可能不需要的类,就不需要再打包的时候导入到其中。
|
||||

|
||||
|
||||
|
||||
|
||||
### 依赖的传递性
|
||||
能够通过依赖传递,导入大量相关的间接依赖。而不需要手动导入所有的依赖。
|
||||
* A依赖B,B依赖C的时候,A不需要引入C即可使用C依赖。A会间接依赖C
|
||||
* compile范围的依赖能够传递,test和provide范围的依赖无法传递。
|
||||
|
||||
|
||||
### 依赖的排除
|
||||
|
||||
阻断依赖的传递性。多个间接依赖可能不兼容,需要排除不兼容的间接依赖。
|
||||
|
||||

|
||||
|
||||
标签位置 dependency/exclusions/exclusion
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId></groupId>
|
||||
<artifactId></artifactId>
|
||||
</exclusion>
|
||||
<exclusions>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### 版本仲裁
|
||||

|
||||
|
||||
1. 最短路径优先
|
||||
2. 路径相同先声明者优先。
|
||||
|
||||
## 3 继承关系parent
|
||||
> 依赖的继承主要是通过parent标签实现的。
|
||||
|
||||
|
||||
### 继承关系
|
||||
Maven工程之间,A工程继承B工程
|
||||
* B工程:父工程
|
||||
* A工程:子工程
|
||||
|
||||
本质上是A工程的pom.xml中的配置继承了B工程中pom.xml的配置。
|
||||
|
||||
继承,也就是父工程,主要管理依赖信息的版本
|
||||
|
||||
### 继承的作用
|
||||
在付工程中统一管理项目中的依赖信息,管理以来信息的版本。
|
||||
|
||||
|
||||
背景
|
||||
* 一个大型的项目进行了模块拆分
|
||||
* 一个project下面创建了很多module
|
||||
* 每一个module都需要自己的依赖信息
|
||||
|
||||
|
||||
需求
|
||||
* 每一个module中各自维护各自的依赖信息很容易发生不一致的情况,不易统一管理
|
||||
* 使用框架内的的不同的jar包,应该是同一个版本,所以整个项目使用的框架版本需要统一
|
||||
* 使用框架时所需要的jar包组合,需要经过长期摸索和反复调试,最终确定一个可用的组合。
|
||||
|
||||
通过在父工程中为整个项目维护依赖信息的组合,既保证了整个项目的使用规范、准确的jar包;又能讲以往的经验沉淀下来,节约时间和精力。
|
||||
|
||||
### 继承的使用
|
||||
|
||||
1. 创建父工程,修改工程的打包方式。只有打包方式为pom的maven工程能够管理其他的maven工程。**打包方式为pom**的maven工程总不写业务代码,是专门管理其他maven工程的工程。
|
||||
|
||||
```xml
|
||||
<groupId>com.ykl</groupId>
|
||||
<artifactId>project-maven</artifactId>
|
||||
<version>1.0.2</version>
|
||||
<packaging>pom</packaging>
|
||||
```
|
||||
|
||||
2. 创建模块工程。idea中的module。从聚合分解的角度分析就是聚合和模块两种工程。而不是父子工程。
|
||||
|
||||
|
||||
3. 模块间的依赖关系
|
||||
1. 在父工程中通过modules来引入子工程
|
||||
2. 在子工程中通过parent引入父工程
|
||||
|
||||
|
||||
|
||||
```xml
|
||||
<parent>
|
||||
<groupId></groupId>
|
||||
<artifactId></artifactId>
|
||||
<version></version>
|
||||
</parent>
|
||||
```
|
||||
4. 在付工程进行依赖信息的统一管理
|
||||
```xml
|
||||
<dependencyManagement>
|
||||
<depencies>
|
||||
<dependency>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
```
|
||||
|
||||
* 并不是在父工程管理了依赖,子工程具体使用哪个依赖,还要明确配置。仅仅是不需要配置版本号。
|
||||
|
||||
* 对于已经在付工程进行管理的依赖,子工程引用时可以不写version
|
||||
* 父子工程版本一致,可以省略了version标签
|
||||
* 父子工程版本冲突,子工程的版本覆盖了父工程中的版本。
|
||||
|
||||
### 继承中的属性
|
||||
|
||||
创建自定以的属性标签,标签名也就是属性名,标签纸也就是属性值。
|
||||
|
||||
引用方式 `$com.ykl.spring.version$`。通过属性名解析后才知道具体的版本号值。
|
||||
|
||||
```xml
|
||||
<properties>
|
||||
<com.ykl.spring.version>4.1.0.RELEASE</com.ykl.spring.version>
|
||||
</properties>
|
||||
|
||||
${com.ykl.spring.version}
|
||||
```
|
||||
### 实际意义
|
||||
|
||||

|
||||
|
||||
* 梳理出一整套版本之间依赖的方案。与我们的火车头版本很想,会总结出一套可以相互兼容没有问题的中间件的合集。
|
||||
|
||||
## 4 聚合关系modules
|
||||
|
||||
### 聚合的含义
|
||||
|
||||
通过moudules标签聚合子项目。好处
|
||||
1. 如果没有聚合标签,或者说聚合功能,则需要去每个模块下执行maven命令,并且按照依赖顺序从前到后执行。
|
||||
1. 如果有聚合标签,可以一键执行maven命令。mvn 会按照模块之间的依赖关系依次执行命令。
|
||||
2. 能够显示各个所有的模块。
|
||||
|
||||
```xml
|
||||
<modules>
|
||||
<module>project04-maven-moduele</module>
|
||||
<module>project05-maven-moduele</module>
|
||||
<module>project06-maven-moduele</module>
|
||||
</modules>
|
||||
```
|
||||
### 循环依赖
|
||||
|
||||
* 防止循环依赖,会出现报错
|
||||
|
||||
```xml
|
||||
the ... dependencies has cyclic dependency
|
||||
|
||||
```
|
||||
## 5 POM的层次
|
||||
|
||||
### 基本概念
|
||||
Maven不仅仅用来做依赖管理和项目构建。还用来做**项目管理**。
|
||||
|
||||
POM有四个层次:超级POM、父POM、当前POM、生效POM
|
||||
|
||||
|
||||
### 超级pom
|
||||
|
||||
默认继承了超级POM。超级POM
|
||||
|
||||
* moduleversion版本信息
|
||||
* repository 仓库的地址
|
||||
* pluginrepostory 插件仓库的地址
|
||||
* builid 主要设置各个目录的位置。
|
||||
* 插件管理
|
||||
* profiles 配置文件
|
||||
|
||||
|
||||
### 父POM
|
||||
> 当前的POM的parent
|
||||
|
||||
|
||||
### 当前POM
|
||||
|
||||
> 下层POM会继承上层POM。最近的有效配置是下层pom
|
||||
|
||||
|
||||
### 有效POM
|
||||
> 最终生效的POM文件,将所有的父POM叠加到一起
|
||||
|
||||
```
|
||||
mvn help:effective-pom
|
||||
```
|
||||
## 6 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.0http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<!--父项目的坐标。如果项目中没有规定某个元素的值,那么父项目中的对应值即为项目的默认值。 坐标包括group ID,artifact ID和
|
||||
@@ -683,249 +898,3 @@ pom.xml 项目模型对象文件。POM 中可以指定以下配置:
|
||||
<properties />
|
||||
</project>
|
||||
```
|
||||
|
||||
## 3 本项目的pom
|
||||
> 有时间对这个进行注释
|
||||
```
|
||||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.0.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.xykj</groupId>
|
||||
<artifactId>wallet-api</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>wallet-api</name>
|
||||
<description>浔银电子钱包接口服务</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<lombok.version>1.18.12</lombok.version>
|
||||
<mybatis.version>2.1.2</mybatis.version>
|
||||
<swagger.version>2.9.2</swagger.version>
|
||||
<zcloud.version>1.0.0</zcloud.version>
|
||||
<jjwt.version>0.9.1</jjwt.version>
|
||||
<fastjson.version>1.2.68</fastjson.version>
|
||||
<hutool.version>5.3.5</hutool.version>
|
||||
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.retry/spring-retry -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.retry</groupId>
|
||||
<artifactId>spring-retry</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-undertow</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all -->
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!--阿里云的短信服务SDK start-->
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>aliyun-java-sdk-core</artifactId>
|
||||
<version>4.5.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>aliyun-java-sdk-dysmsapi</artifactId>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--阿里云的短信服务SDK end-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
<version>1.9.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<!--Zcloud依赖-->
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>com.zxw.zcloud</groupId>-->
|
||||
<!--<artifactId>xxljob-boot-starter</artifactId>-->
|
||||
<!--<version>${zcloud.version}</version>-->
|
||||
<!--</dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zxw.zcloud</groupId>
|
||||
<artifactId>db-spring-boot-starter</artifactId>
|
||||
<version>${zcloud.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zxw.zcloud</groupId>
|
||||
<artifactId>swagger-spring-boot-starter</artifactId>
|
||||
<version>${zcloud.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zxw.zcloud</groupId>
|
||||
<artifactId>cache-spring-boot-starter</artifactId>
|
||||
<version>${zcloud.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zxw.zcloud</groupId>
|
||||
<artifactId>license-boot-starter</artifactId>
|
||||
<version>${zcloud.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
<version>${jjwt.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--微信公众号-->
|
||||
<dependency>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>weixin-java-mp</artifactId>
|
||||
<version>3.8.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-core</artifactId>
|
||||
<version>5.2.1.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>1.5.20</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.xmlunit</groupId>
|
||||
<artifactId>xmlunit-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<version>3.5.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
<version>3.11.4</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<!--<repository>-->
|
||||
<!--<id>public</id>-->
|
||||
<!--<name>aliyun nexus</name>-->
|
||||
<!--<url>http://maven.aliyun.com/nexus/content/groups/public/</url>-->
|
||||
<!--<releases>-->
|
||||
<!--<enabled>true</enabled>-->
|
||||
<!--</releases>-->
|
||||
<!--</repository>-->
|
||||
<repository>
|
||||
<id>zclod</id>
|
||||
<name>zcloud nexus</name>
|
||||
<url>http://maven.zoujy.com/repository/zcloud_group/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>public</id>
|
||||
<name>zcloud nexus</name>
|
||||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||
<!--<url>http://maven.zoujy.com/repository/zcloud_group/</url>-->
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
</project>
|
||||
|
||||
```
|
||||
32
maven/03 maven与Idea.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# Idea的使用
|
||||
|
||||
## 1 创建工程
|
||||
|
||||
1. 创建maven工程。可以选择archetype创建模板工程,也可以不选,创建标准工程。
|
||||
2. 配置项目。基本配置包括groupId、artifactId、version
|
||||
3. maven的配置。在setting/preference自定义maven的位置,加载maven的仓库位置,而不是使用Idea集成的maven。可以通过maven工具窗口。
|
||||
4. 创建Java模块工程。在父工程中自动添加modules和package
|
||||
|
||||
|
||||
## 2 侧边栏使用
|
||||
|
||||
|
||||
1. 扳手:配置maven
|
||||
2. 打开关闭目录
|
||||
3. M:表示执行maven命令
|
||||
|
||||
|
||||
## 3 工程导入
|
||||
|
||||
### 导入整个工程
|
||||
IDEA直接打开目录就能识别。含有parent-pom的目录
|
||||
|
||||
### 导入单个模块
|
||||
|
||||
project-structures Import module导入基本组件。
|
||||
|
||||
project-structures Import facets导入Web组件
|
||||
|
||||
|
||||
## 4 生命周期
|
||||
提高构件过程的自动化程度。
|
||||
@@ -1,26 +1,35 @@
|
||||
## 一个普通项目的生命周期
|
||||
## 1 命令构成
|
||||
|
||||

|
||||
> 生命周期、插件和目标
|
||||
### 基本命令
|
||||
|
||||
| 阶段 |处理 |描述|
|
||||
|-|-|-|-|
|
||||
| 验证 validate |验证项目 |验证项目是否正确且所有必须信息是可用的|
|
||||
| 编译 compile |执行编译 |源代码编译在此阶段完成|
|
||||
| 测试 Test |测试 |使用适当的单元测试框架(例如JUnit)运行测试。|
|
||||
| 包装 package |打包 |创建JAR/WAR包如在 pom.xml 中定义提及的包|
|
||||
| 检查 verify |检查 |对集成测试的结果进行检查,以保证质量达标|
|
||||
| 安装 install |安装 |安装打包的项目到本地仓库,以供其他项目使用|
|
||||
| 部署 deploy |部署 |拷贝最终的工程包到远程仓库中,以共享给其他开发人员和工程|
|
||||
* 主命令
|
||||
* 插件
|
||||
* 子命令
|
||||
|
||||
## maven项目的三个生命周期
|
||||

|
||||
|
||||
### clean生命周期:清理项目,包含三个phase。
|
||||
|
||||
|
||||
|
||||
* 添加-Dmaven.test.skip=true表示跳过执行。
|
||||

|
||||
|
||||
|
||||
## 2 maven项目的生命周期
|
||||
|
||||
|
||||
> maven项目开发主要包括以下三个生命周期
|
||||
### clean生命周期
|
||||
|
||||
清理项目,包含三个phase。
|
||||
|
||||
1. pre-clean:执行清理前需要完成的工作
|
||||
2. clean:清理上一次构建生成的文件
|
||||
3. post-clean:执行清理后需要完成的工作
|
||||
|
||||
### default生命周期:构建项目,重要的phase如下。
|
||||
### default生命周期
|
||||
构建项目,重要的phase如下。
|
||||
|
||||
1. validate:验证工程是否正确,所有需要的资源是否可用。
|
||||
1. compile:编译项目的源代码。
|
||||
@@ -31,9 +40,27 @@
|
||||
1. install:把包安装到maven本地仓库,可以被其他工程作为依赖来使用。
|
||||
1. Deploy:在集成或者发布环境下执行,将最终版本的包拷贝到远程的repository,使得其他的开发者或者工程可以共享。
|
||||
|
||||
### site生命周期:建立和发布项目站点,phase如下
|
||||
### site生命周期
|
||||
建立和发布项目站点,phase如下
|
||||
|
||||
1. pre-site:生成项目站点之前需要完成的工作
|
||||
2. site:生成项目站点文档
|
||||
3. post-site:生成项目站点之后需要完成的工作
|
||||
4. site-deploy:将项目站点发布到服务器
|
||||
4. site-deploy:将项目站点发布到服务器
|
||||
|
||||
|
||||
## 3 maven命令
|
||||
|
||||
三个生命周期是独立的。maven命令是按顺序依次执行的。每次执行都会将同一周期之前的命令执行一遍。
|
||||
|
||||
<!--  -->
|
||||
|
||||
| 阶段 |处理 |描述|
|
||||
|-|-|-|-|
|
||||
| 验证 validate |验证项目 |验证项目是否正确且所有必须信息是可用的|
|
||||
| 编译 compile |执行编译 |源代码编译在此阶段完成|
|
||||
| 测试 Test |测试 |使用适当的单元测试框架(例如JUnit)运行测试。|
|
||||
| 包装 package |打包 |创建JAR/WAR包如在 pom.xml 中定义提及的包|
|
||||
| 检查 verify |检查 |对集成测试的结果进行检查,以保证质量达标|
|
||||
| 安装 install |安装 |安装打包的项目到本地仓库,以供其他项目使用|
|
||||
| 部署 deploy |部署 |拷贝最终的工程包到远程仓库中,以共享给其他开发人员和工程|
|
||||
@@ -3,7 +3,7 @@
|
||||
## 1 仓库简介
|
||||
|
||||
仓库是项目中依赖的第三方库。任何一个依赖、插件或者项目构建输出,都可以称之为构件。maven仓库能够帮我们管理构件(比如jar程序)。maven仓库有3中类型,本地、中央、远程。
|
||||
|
||||

|
||||
## 2 本地仓库
|
||||
|
||||
第一次运行maven仓库时,创建本地仓库。maven所需要的构建都是直接从本地仓库获取的。如果本地仓库没有,会首先尝试从远程仓库下载值本地仓库,然后使用本地仓库的构件。
|
||||
274
maven/06 maven命令插件Plugins.md
Normal file
@@ -0,0 +1,274 @@
|
||||
## 1 简介
|
||||
|
||||
### 插件概念
|
||||
maven项目包含三个生命周期,每个生命周期包含多个节点。每个节点都是由maven插件实现。例如maven-clean-plugin
|
||||
|
||||
maven实际上是一个依赖插件执行的框架。
|
||||
|
||||
插件提供了一个目标的集合。使用以下语法执行
|
||||
```
|
||||
mvn [plugin-name]:[goal-name]
|
||||
mvn compiler:compile
|
||||
```
|
||||
|
||||
### 插件与生命周期
|
||||
插件可以通过phase标签绑定到指定的生命周期环境。而在执行命令的时候,会执行该生命周期之前的所有生命周期关联的插件。
|
||||
|
||||
|
||||
### 配置额外的插件
|
||||
在项目的build标签中,添加plugins/plugin标签,然后进行配置。
|
||||
* plugin的坐标groupId/artifactId/version
|
||||
* execution 插件的id和绑定的生命周期phase。
|
||||
* execution 插件的名称和目标goal。
|
||||
```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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.companyname.projectgroup</groupId>
|
||||
<artifactId>project</artifactId>
|
||||
<version>1.0</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>id.clean</id>
|
||||
<phase>clean</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<echo>clean phase</echo>
|
||||
</tasks>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
```
|
||||
|
||||
|
||||
## 2 常用插件
|
||||
|
||||
|
||||
分为两类
|
||||
* Build plugins
|
||||
* Repoting plugins
|
||||
|
||||
常用插件列表
|
||||
|
||||
* clean 构建之后清理目标文件。删除目标目录。
|
||||
* compiler 编译 Java 源文件。
|
||||
* surefile 运行 JUnit 单元测试。创建测试报告。
|
||||
* jar 从当前工程中构建 JAR 文件。
|
||||
* war 从当前工程中构建 WAR 文件。
|
||||
* javadoc 为工程生成 Javadoc。
|
||||
* antrun 从构建过程的任意一个阶段中运行一个 ant 任务的集合。
|
||||
|
||||
### help插件:分析依赖
|
||||

|
||||
|
||||
|
||||
### archetype插件:创建工程
|
||||
|
||||
```
|
||||
mvn archetype:generate -DgroupId=com.ykl -DartifactId=project04-maven-import -DarchetypeArtifactId=maven-archetype-quickstart -Dversion=0.0.1-snapshot
|
||||
```
|
||||
|
||||
|
||||
|
||||
### mvn差价dependcy:依赖管理和分析
|
||||
|
||||
|
||||
* 查看依赖列表
|
||||
|
||||
```
|
||||
mvn dependcy:list
|
||||
mvn dependcy:tree
|
||||
```
|
||||
### spring-boot-maven-plugin
|
||||
|
||||
spring-boot-maven-plugin是spring boot提供的maven打包插件。可打直接可运行的jar包或war包。
|
||||
|
||||
```xml
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
```
|
||||
插件提供了6个maven goal
|
||||
|
||||
* build-info:生成项目的构建信息文件 build-info.properties
|
||||
* help:用于展示spring-boot-maven-plugin的帮助信息。使用命令行mvn spring-boot:help -Ddetail=true -Dgoal=<goal-name>可展示goal的参数描述信息。
|
||||
* repackage:可生成可执行的jar包或war包。插件的核心goal。
|
||||
* run:运行 Spring Boot 应用
|
||||
* start:在集成测试阶段,控制生命周期
|
||||
* stop:在集成测试阶段,控制生命周期
|
||||
|
||||
## 2 自定义插件
|
||||
|
||||
### 创建工程
|
||||
```shell
|
||||
➜ maven源码 git:(master) ✗ mvn archetype:generate -DgroupId=com.ykl -DartifactId=project05-maven-plugin -DarchetypeArtifactId=maven-archetype-quickstart -Dversion=0.0.1-snapshot
|
||||
```
|
||||
### 打包方式
|
||||
|
||||
```
|
||||
<pakaging>maven-plugin</pakaging>
|
||||
```
|
||||
|
||||
### maven依赖
|
||||

|
||||
|
||||
下面两种方式二选一:
|
||||
|
||||
```xml
|
||||
#[1]将来在文档注释中使用注解
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>3.5.2</version>
|
||||
</dependency>
|
||||
#[2]将来直接使用注解
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||
<artifactId>maven-plugin-annotations</artifactId>
|
||||
<version>3.5.2</version>
|
||||
</dependency>
|
||||
```
|
||||
### 创建Mojo类
|
||||
|
||||
maven old java object maven的核心类。每一个 Mojo 都需要实现 org.apache.maven.plugin.Mojo 接口。
|
||||
|
||||
|
||||

|
||||
|
||||
|
||||
```java
|
||||
public class MyHelloPlugin extends AbstractMojo {
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
getLog().info("---> This is my first maven plugin. <---");
|
||||
}
|
||||
}
|
||||
```
|
||||
### 添加注解标识
|
||||
* 文档注释中用注解:对应的 pom.xml 中的依赖: maven-plugin-api
|
||||

|
||||
|
||||
|
||||
* 直接在类上标记注解:对应 pom.xml 中的依赖:maven-plugin-annotations
|
||||
```
|
||||
// name 属性:指定目标名称
|
||||
@Mojo(name = "firstBlood")
|
||||
public class MyPluginOfFistBlood extends AbstractMojo {
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
getLog().info("---> first blood <---");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 安装插件
|
||||
要在后续使用插件,就必须至少将插件安装到本地仓库。
|
||||
|
||||
```
|
||||
mvn clean install
|
||||
```
|
||||
|
||||
### 注册插件。
|
||||
|
||||
我们需要将插件坐标中的 groupId 部分注册到 settings.xml 中。再pluginGroups声明插件仓库。
|
||||
|
||||
```xml
|
||||
<pluginGroups>
|
||||
<!-- pluginGroup
|
||||
| Specifies a further group identifier to use for plugin lookup.
|
||||
<pluginGroup>com.your.plugins</pluginGroup>
|
||||
-->
|
||||
<pluginGroup>com.ykl</pluginGroup>
|
||||
</pluginGroups>
|
||||
```
|
||||
|
||||

|
||||
|
||||
### 使用插件
|
||||
|
||||
Maven 根据插件的 artifactId 来识别插件前缀。例如下面两种情况:
|
||||
```
|
||||
#[1]前置匹配
|
||||
匹配规则:${prefix}-maven-plugin
|
||||
artifactId:hello-maven-plugin
|
||||
前缀:hello
|
||||
#[2]中间匹配
|
||||
匹配规则:maven-${prefix}-plugin
|
||||
artifactId:maven-good-plugin
|
||||
前缀:good
|
||||
```
|
||||
|
||||
**在命令行直接用**
|
||||
|
||||
命令:
|
||||
```
|
||||
mvn hello:sayHello
|
||||
```
|
||||
效果:
|
||||

|
||||
|
||||
**配置到build标签里**
|
||||
这里找一个和插件无关的 Maven 工程配置才有说服力。
|
||||
```
|
||||
#[1]配置
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.atguigu.maven</groupId>
|
||||
<artifactId>hello-maven-plugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>hello</id>
|
||||
<!-- 指定和目标关联的生命周期阶段 -->
|
||||
<phase>clean</phase>
|
||||
<goals>
|
||||
<goal>sayHello</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>blood</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>firstBlood</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
```
|
||||
效果
|
||||

|
||||
|
||||
**图形化界面使用**
|
||||
|
||||

|
||||
|
||||
**命令行使用**
|
||||
执行已和插件目标绑定的生命周期:
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
@@ -40,4 +40,24 @@ mvn clean package
|
||||
运行文档生成
|
||||
```
|
||||
mvn site
|
||||
```
|
||||
```
|
||||
|
||||
## 5 引入外部依赖到项目中
|
||||
在src下创建lib文件夹,用来防止第三方的jar文件。
|
||||
```
|
||||
<dependencies>
|
||||
<!-- 在这里添加你的依赖 -->
|
||||
<dependency>
|
||||
<groupId>ldapjdk</groupId> <!-- 库名称,也可以自定义 -->
|
||||
<artifactId>ldapjdk</artifactId> <!--库名称,也可以自定义-->
|
||||
<version>1.0</version> <!--版本号-->
|
||||
<scope>system</scope> <!--作用域-->
|
||||
<systemPath>${basedir}\src\lib\ldapjdk.jar</systemPath> <!--项目根目录下的lib文件夹下-->
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
|
||||
### 引入外部依赖到本地中
|
||||
|
||||
可以直接下载到当前的mvn本地仓库中。.m2/repository
|
||||
|
||||
148
maven/08 maven属性标签Properties.md
Normal file
@@ -0,0 +1,148 @@
|
||||
# 属性的生命与使用
|
||||
|
||||
|
||||
## 1 自定义maven属性值
|
||||
|
||||
### 创建属性值
|
||||
```
|
||||
<properties>
|
||||
<com.ykl.hello>temp</com.ykl.hello>
|
||||
<com.ykl.world>world</com.ykl.world>
|
||||
</properties>
|
||||
```
|
||||
|
||||
### 查看属性值
|
||||
```
|
||||
mvn help:evaluate
|
||||
```
|
||||
|
||||
### 访问属性值
|
||||
|
||||
```
|
||||
${a.b}
|
||||
```
|
||||
|
||||
## 2 maven中的其他属性
|
||||
|
||||
### maven访问的系统属性
|
||||
|
||||

|
||||
这里的系统属性指的是Java虚拟机中定义的变量。
|
||||
|
||||
```java
|
||||
Properties properties = System.getProperties();
|
||||
|
||||
Set<Object> properitesSet = properties.keySet();
|
||||
|
||||
for (Object propName :propertiesSet){
|
||||
String propValue = properties.getProperty((String)propName);
|
||||
System.out.println(propName + ": " + propValue);
|
||||
}
|
||||
```
|
||||
|
||||
得到如下的结果
|
||||
|
||||
```shell
|
||||
java.runtime.name: Java(TM) SE Runtime Environment
|
||||
sun.boot.library.path: /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib
|
||||
java.vm.version: 25.291-b10
|
||||
gopherProxySet: false
|
||||
java.vm.vendor: Oracle Corporation
|
||||
java.vendor.url: http://java.oracle.com/
|
||||
path.separator: :
|
||||
java.vm.name: Java HotSpot(TM) 64-Bit Server VM
|
||||
file.encoding.pkg: sun.io
|
||||
user.country: CN
|
||||
sun.java.launcher: SUN_STANDARD
|
||||
sun.os.patch.level: unknown
|
||||
java.vm.specification.name: Java Virtual Machine Specification
|
||||
user.dir: /Users/yinkanglong/work/notes/maven/maven源码/project01-maven-java/target/classes
|
||||
java.runtime.version: 1.8.0_291-b10
|
||||
java.awt.graphicsenv: sun.awt.CGraphicsEnvironment
|
||||
java.endorsed.dirs: /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/endorsed
|
||||
os.arch: x86_64
|
||||
java.io.tmpdir: /var/folders/w5/xwpp23dd6qxfb4b8kw2512nr0000gp/T/
|
||||
line.separator:
|
||||
|
||||
java.vm.specification.vendor: Oracle Corporation
|
||||
os.name: Mac OS X
|
||||
sun.jnu.encoding: UTF-8
|
||||
java.library.path: /Users/yinkanglong/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
|
||||
java.specification.name: Java Platform API Specification
|
||||
java.class.version: 52.0
|
||||
sun.management.compiler: HotSpot 64-Bit Tiered Compilers
|
||||
os.version: 10.16
|
||||
user.home: /Users/yinkanglong
|
||||
user.timezone:
|
||||
java.awt.printerjob: sun.lwawt.macosx.CPrinterJob
|
||||
file.encoding: UTF-8
|
||||
java.specification.version: 1.8
|
||||
java.class.path: .
|
||||
user.name: yinkanglong
|
||||
java.vm.specification.version: 1.8
|
||||
sun.java.command: com.ykl.App
|
||||
java.home: /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre
|
||||
sun.arch.data.model: 64
|
||||
user.language: zh
|
||||
java.specification.vendor: Oracle Corporation
|
||||
awt.toolkit: sun.lwawt.macosx.LWCToolkit
|
||||
java.vm.info: mixed mode
|
||||
java.version: 1.8.0_291
|
||||
java.ext.dirs: /Users/yinkanglong/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
|
||||
sun.boot.class.path: /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home/jre/classes
|
||||
java.vendor: Oracle Corporation
|
||||
file.separator: /
|
||||
java.vendor.url.bug: http://bugreport.sun.com/bugreport/
|
||||
sun.io.unicode.encoding: UnicodeBig
|
||||
sun.cpu.endian: little
|
||||
sun.cpu.isalist:
|
||||
```
|
||||
|
||||
### maven能够访问的系统环境变量
|
||||
使用env前缀能够访问系统环境变量
|
||||

|
||||
这里的系统环境变量指的是操作系统env中当前定义的变量
|
||||
通过`${env.JAVA_HOME}`实现。
|
||||
```
|
||||
[INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?:
|
||||
${env.JAVA_HOME}
|
||||
[INFO]
|
||||
/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home
|
||||
```
|
||||
|
||||
|
||||
### maven 能够访问POM标签
|
||||
使用 project前缀可以访问POM标签
|
||||

|
||||

|
||||
|
||||
使用表达式`${project.xxx}`可以访问当前POM中定义的元素值。也就是POM中配置的任何元素都可以用属性值进行访问解析。
|
||||
|
||||
```
|
||||
[INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?:
|
||||
${project.groupId}
|
||||
[INFO]
|
||||
org.apache.maven
|
||||
```
|
||||
|
||||
### maven能够访问settings全局配置
|
||||

|
||||
|
||||
使用settings前缀访问settingsxml中配置文件
|
||||
|
||||
```xml
|
||||
[INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?:
|
||||
${settings.localRepository}
|
||||
[INFO]
|
||||
/Users/yinkanglong/.m2/repository
|
||||
```
|
||||
|
||||
|
||||
## 3 maven属性的用途
|
||||
|
||||
在当前的pom.xml文件中引用属性
|
||||
|
||||
资源过滤功能:在非maven配置文件中引用属性,由于maven在处理资源师将引用属性的表达式替换为属性值。
|
||||
|
||||
针对不同环境的profile一般不常用,一般是在框架中做的。
|
||||
|
||||
232
maven/09 maven构建标签Build.md
Normal file
@@ -0,0 +1,232 @@
|
||||
## 1 概述
|
||||
|
||||
本质上配置的Build标签是对超级POM配置的Build标签的叠加。(猜想 sofaboot的目录结构也是通过build标签定义了约定的目录结构。)
|
||||
|
||||
|
||||
## 2 作用
|
||||
### 配置约定的目录结构Dir
|
||||
|
||||

|
||||
```
|
||||
<build>
|
||||
<sourceDirectory>/Users/yinkanglong/work/notes/maven/maven源码/project03-maven-test/src/main/java</sourceDirectory>
|
||||
<scriptSourceDirectory>/Users/yinkanglong/work/notes/maven/maven源码/project03-maven-test/src/main/scripts</scriptSourceDirectory>
|
||||
<testSourceDirectory>/Users/yinkanglong/work/notes/maven/maven源码/project03-maven-test/src/test/java</testSourceDirectory>
|
||||
<outputDirectory>/Users/yinkanglong/work/notes/maven/maven源码/project03-maven-test/target/classes</outputDirectory>
|
||||
<testOutputDirectory>/Users/yinkanglong/work/notes/maven/maven源码/project03-maven-test/target/test-classes</testOutputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>/Users/yinkanglong/work/notes/maven/maven源码/project03-maven-test/src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>/Users/yinkanglong/work/notes/maven/maven源码/project03-maven-test/src/test/resources</directory>
|
||||
</testResource>
|
||||
</testResources>
|
||||
<directory>/Users/yinkanglong/work/notes/maven/maven源码/project03-maven-test/target</directory>
|
||||
<finalName>project03-maven-test-0.0.1-snapshot</finalName>
|
||||
|
||||
```
|
||||
|
||||
### 备用插件管理pluginManagement
|
||||
|
||||
pluginManagement标签存放着多个插件
|
||||
|
||||
* maven-antrun-plugin
|
||||
* maven-assembly-plugin
|
||||
* mavne-dependency-plugin
|
||||
* maven-release-plugin
|
||||
|
||||
通过pluginMangement标签管理起来的插件,和dependencyManagement一样。子工程使用时可以忽略版本号,在父工程中统一管理版本。父子工程仍旧能够起到版本管理的作用。
|
||||
|
||||
* spring-boot-dependencies管理的插件信息
|
||||
```
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>${build-helper-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-maven-plugin</artifactId>
|
||||
<version>${flyway.version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>pl.project13.maven</groupId>
|
||||
<artifactId>git-commit-id-plugin</artifactId>
|
||||
<version>${git-commit-id-plugin.version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
```
|
||||
|
||||
### 生命周期插件plugins
|
||||
|
||||
plugins 标签存放的是默认生命周期中实际会用到的插件。这是正式使用的插件。正如dependencyManagement一样,是备用的依赖。
|
||||
|
||||
* 是execution不是exculusion
|
||||
|
||||
```xml
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-clean</id>
|
||||
<phase>clean</phase>
|
||||
<goals>
|
||||
<goal>clean</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>2.5.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-install</id>
|
||||
<phase>install</phase>
|
||||
<goals>
|
||||
<goal>install</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.8.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-deploy</id>
|
||||
<phase>deploy</phase>
|
||||
<goals>
|
||||
<goal>deploy</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-site</id>
|
||||
<phase>site</phase>
|
||||
<goals>
|
||||
<goal>site</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>/Users/yinkanglong/work/notes/maven/maven源码/project03-maven-test/target/site</outputDirectory>
|
||||
<reportPlugins>
|
||||
<reportPlugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
</reportPlugin>
|
||||
</reportPlugins>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>default-deploy</id>
|
||||
<phase>site-deploy</phase>
|
||||
<goals>
|
||||
<goal>deploy</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>/Users/yinkanglong/work/notes/maven/maven源码/project03-maven-test/target/site</outputDirectory>
|
||||
<reportPlugins>
|
||||
<reportPlugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
</reportPlugin>
|
||||
</reportPlugins>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<outputDirectory>/Users/yinkanglong/work/notes/maven/maven源码/project03-maven-test/target/site</outputDirectory>
|
||||
<reportPlugins>
|
||||
<reportPlugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
</reportPlugin>
|
||||
</reportPlugins>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
```
|
||||
|
||||
## 3 典型应用
|
||||
|
||||
### source标签和target标签
|
||||
* Idea读取的是maven的settings.xml种jdk的版本进行编译的执行。
|
||||
* 在settings.xml中的profile配置的jdk版本,注释掉。则IDEA无法正常调用指定版本的jdk编译器,编译程序。
|
||||
* 在plugins能够通过指定jdk的版本,实现当前步骤的正常编译。
|
||||
* source的配置就是指定的版本。java编译的时候的source参数
|
||||
* target是调用编译器时指定的。java编译的时候target参数。
|
||||
|
||||

|
||||
|
||||
|
||||
* 在settings.xml中配置jdk版本:尽在本地剩下,如果驼鹿当前settings。xml能够覆盖的范围,则无法生效
|
||||
* 在当前maven工程的pom.xml种配置:无论在哪个环境执行编译等构建操作都有效。
|
||||
|
||||
|
||||
### springboot定制化打包
|
||||
|
||||
* Spring-boot-maven-plugin,用来改变maven默认的构建行为。具体来说就是改变打包的行为。
|
||||
* 默认情况下maven调用maven-jar-plugin插件的jar目标,生成普通的jar
|
||||
* 普通jar没办法通过java -jar xxx.jar命令启动运行,
|
||||
* 但是Springboot的设计理念就是每一个微服务导出一个jar包。这个jar包可以使用jar -jar命令直接启动。例如需要web的时候,就需要讲tomcat等插件打包到一起。
|
||||
* 使用方式,配置Spring-boot-maven-plugin插件。即可使用springboot的打包方式进行打包。
|
||||
|
||||
```xml
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>2.6.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
```
|
||||
|
||||
插件提供了6个maven goal
|
||||
|
||||
* build-info:生成项目的构建信息文件 build-info.properties
|
||||
* help:用于展示spring-boot-maven-plugin的帮助信息。使用命令行mvn spring-boot:help -Ddetail=true -Dgoal=<goal-name>可展示goal的参数描述信息。
|
||||
* repackage:可生成可执行的jar包或war包。插件的核心goal。
|
||||
* run:运行 Spring Boot 应用
|
||||
* start:在集成测试阶段,控制生命周期
|
||||
* stop:在集成测试阶段,控制生命周期
|
||||
|
||||
|
||||
### mybatis的逆向工程
|
||||
|
||||
插件也可以有自己的依赖。
|
||||
|
||||

|
||||
|
||||
|
||||
### resources
|
||||
|
||||
resource可以配置资源过滤
|
||||
|
||||
* directory指定资源过滤的目录
|
||||
* filtering是否打开资源过滤
|
||||
* include 包含资源过滤的文件
|
||||
* exclude 排除资源过滤的文件。不会被打包的target目标文件夹当中。
|
||||
|
||||
|
||||

|
||||
|
||||
## 总结
|
||||
|
||||
maven的POM中的一些内容。
|
||||
@@ -1,15 +1,67 @@
|
||||
## 1 配置文件的类型
|
||||
## 1 配置文件
|
||||
|
||||
* 项目级:定义在项目的POM文件pom.xml中。
|
||||
* 用户级:定义在maven的设置文件xml中(%USER_HOME%.m2/setting.xml)
|
||||
* 全局:定义在Maven全局的设置xml文件中(%M2_HOME%/comf/settings.xml)
|
||||
|
||||
## 配置文件激活
|
||||
|
||||
### 配置文件激活
|
||||
### 配置文件概述
|
||||
|
||||
profile 可以让我们定义一系列的配置信息,然后指定其激活条件。这样我们就可以定义多个 profile,然后每个 profile 对应不同的激活条件和配置信息,从而达到不同环境使用不同配置信息的效果。
|
||||
|
||||
* profiles/profile 代表众多可选配置中的一个,所以使用profiles附属形式进行管理。
|
||||
* 由于profile标签覆盖了pom.xml中的默认配置(能够覆盖任何之前的配置),所以profiles标签通常是pom.xml
|
||||
```xml
|
||||
<profile>
|
||||
<id>test</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>env</name>
|
||||
<value>test</value>
|
||||
</property>
|
||||
<!-- <activeByDefault>true</activeByDefault> -->
|
||||
</activation>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>central</id>
|
||||
<url>http://mvn.test.alipay.net:8080/artifactory/repo</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>snapshots</id>
|
||||
<url>http://mvn.test.alipay.net:8080/artifactory/repo</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>never</updatePolicy>
|
||||
</releases>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>alibaba</id>
|
||||
<url>http://mvnrepo.alibaba-inc.com/mvn/repository</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>central</id>
|
||||
<url>http://mvn.test.alipay.net:8080/artifactory/repo</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
<updatePolicy>never</updatePolicy>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>alibaba</id>
|
||||
<url>http://mvnrepo.alibaba-inc.com/mvn/repository</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
</profile>
|
||||
</profiles>
|
||||
```
|
||||
|
||||
|
||||
* activation标签:激活的方式
|
||||
* activeByDefault表示默认激活
|
||||
* properties表示一旦被激活后采纳的配置
|
||||
* id是名字
|
||||
|
||||
## 2 maven配置文件的激活方式
|
||||
### 通过maven设置激活配置文件
|
||||
|
||||
通过Maven设置激活配置文件
|
||||
@@ -165,3 +217,25 @@ activation 元素包含下面的操作系统信息。当系统为 windows XP 时
|
||||
</activation>
|
||||
</profile>
|
||||
```
|
||||
### 使用命令进行激活
|
||||
|
||||
查看当前环境激活的profile
|
||||
```
|
||||
mvn help:active-profiles
|
||||
```
|
||||
激活某个指定id的profile
|
||||
```
|
||||
mvn compile -P <profile id>
|
||||
```
|
||||
|
||||
## 3 实例
|
||||
|
||||
### 编写lambda表达式
|
||||
|
||||
|
||||
|
||||
## 4 资源属性过滤
|
||||
> 一般不用
|
||||
|
||||
### 过滤资源
|
||||
* 使用资源处理功能,处理解析指定目下的`${}`变量。
|
||||
49
maven/11 maven私服Nexus.md
Normal file
@@ -0,0 +1,49 @@
|
||||
用于快速的模块化的版本迭代。
|
||||
|
||||
|
||||
## 1 步骤
|
||||
|
||||
1. 下载nexus的执行程序。也可以直接下载nexus的docker,然后运行。
|
||||
|
||||
|
||||
2. 运行启动nexus执行程序,并查看nexus占用的端口号。
|
||||
```
|
||||
netstat anl |grep nexus
|
||||
```
|
||||
|
||||
3. 然后登录nexus服务器的管理端。
|
||||
|
||||
|
||||
4. 复制黏贴自己的私服地址和用户名密码到settings.xml当中。
|
||||
|
||||
|
||||
5. 配置当前工程pom中的distributionManagement
|
||||

|
||||
|
||||
6. 执行部署。默认情况下,mvn deploy会不数到上述配置中的仓库里。
|
||||
|
||||
|
||||
7. 使用别人部署的jar。必须配置别人部署的nexus仓库。
|
||||
|
||||
|
||||
|
||||
|
||||
## 2 概述
|
||||
|
||||
nexus仓库的仓库
|
||||

|
||||
|
||||
|
||||
nexus仓库的类型
|
||||

|
||||
|
||||
|
||||
nexus仓库的名称
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
## 3 实验实践
|
||||
|
||||
|
||||
134
maven/12 maven依赖冲突.md
Normal file
@@ -0,0 +1,134 @@
|
||||
# jar包冲突问题
|
||||
|
||||
## 1 解决依赖冲突
|
||||
|
||||
### 冲突的引入
|
||||
1. 编订依赖列表的时候需要解决依赖冲突
|
||||
2. 在引入多个jar包时产生了冲突
|
||||
|
||||
### 冲突的本质
|
||||
* 统一jar包,不同版本(名称不一样,版本仲裁机制无法生效,导入了多个包,或者仲裁的包错误)
|
||||

|
||||
* 不同jar包包含同类名(全限定名相同的类)
|
||||

|
||||
|
||||
|
||||
## 2 表现形式
|
||||
|
||||
表现形式:整个错误信息全部是框架、第三方工具包中的类报错,往往就是jar包的问题引起的。并且maven的版本仲裁机制无法生效的情况下。
|
||||
|
||||
### 抛异常:找不到类
|
||||
|
||||
* java.lang.ClassNotFoundException:编译过程找不到类
|
||||
* java.lang.NoClassDefFoundError:运行过程找不到类
|
||||
* java.lang.LinkageError:不同类加载器分别加在的多个类具有相同的全类名。
|
||||
|
||||
### 抛异常找不到哦啊方法
|
||||
* java.lang.NoSuchMethodException:反射过程找不到类。
|
||||
* 经过仲裁选中了版本,但是显示包中没有该版本的方法。
|
||||
|
||||
### 没有报错单结果不对
|
||||
* 两个 jar 包中的类分别实现了同一个接口,这本来是很正常的。但是问题在于:由于没有注意命名规范,两个不同实现类恰巧是同一个名字。
|
||||
* 具体例子是有的同学在实际工作中遇到过:项目中部分模块使用 log4j 打印日志;其它模块使用 logback,编译运行都不会冲突,但是会引起日志服务降级,让你的 log 配置文件失效。比如:你指定了 error 级别输出,但是冲突就会导致 info、debug 都在输出。
|
||||
|
||||
|
||||
|
||||
## 解决方法
|
||||
|
||||
1. 找到冲突的jar包。
|
||||
2. 把彼此冲突的jar包解决掉。
|
||||
1. exclusions排除
|
||||
2. 明确声明依赖。
|
||||
|
||||
|
||||
### IDEA中找到依赖冲突
|
||||
|
||||
在IDEA中安装maven helper插件。基于pom.xml的依赖冲突分析。能够分析冲突的版本,但不能分析冲突的全类名。
|
||||
* 在POM文件下有Analyzer标签。打开可以看到依赖列表、冲突列表。查找所有依赖、展开依赖列表等。
|
||||
|
||||
也可以使用idea自带的maven功能,也能自动分析maven工程,查看依赖树和查找依赖包。
|
||||
|
||||
|
||||
### maven的enforcer插件
|
||||
|
||||
检测同一个jar包的不同版本和不同jar包中的同类名。
|
||||
|
||||
1. 配置build enforcer插件
|
||||
|
||||
```xml
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>1.4.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-dependencies</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>display-info</goal>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>extra-enforcer-rules</artifactId>
|
||||
<version>1.0-beta-4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<configuration>
|
||||
<rules>
|
||||
<banDuplicateClasses>
|
||||
<findAllDuplicates>true</findAllDuplicates>
|
||||
</banDuplicateClasses>
|
||||
</rules>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
```
|
||||
2. 执行冲突分析命令
|
||||
```
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>1.4.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-dependencies</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>display-info</goal>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>extra-enforcer-rules</artifactId>
|
||||
<version>1.0-beta-4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<configuration>
|
||||
<rules>
|
||||
<banDuplicateClasses>
|
||||
<findAllDuplicates>true</findAllDuplicates>
|
||||
</banDuplicateClasses>
|
||||
</rules>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
```
|
||||
|
||||
3. 查看并分析冲突的内容
|
||||
|
||||

|
||||
127
maven/13 maven导入普通jar.md
Normal file
@@ -0,0 +1,127 @@
|
||||
|
||||
## 1 概述
|
||||
|
||||
|
||||
### 提出问题
|
||||
|
||||
而实际开发中确实有可能用到一些 jar 包并非是用 Maven 的方式发布,那自然也没法通过 Maven 导入。
|
||||
|
||||
此时如果我们能够拿到该 jar 包的源码那还可以自己建一个 Maven 工程,自己打包。
|
||||
|
||||
## 2 手动打包一个可执行文件
|
||||
|
||||
1. 生成.class 文件。利用javac命令进行编译
|
||||
```sh
|
||||
➜ src git:(master) ✗ javac com/ykl/Main.java -d ./out/
|
||||
➜ src git:(master) ✗ ls
|
||||
com out
|
||||
```
|
||||
|
||||
2. 编写manifest文件。manifest文件命名和格式按照要求,可以少写几个参数。
|
||||
|
||||
```
|
||||
➜ out git:(master) ✗ cat MANIFEST.MF
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: com.ykl.Main
|
||||
```
|
||||
|
||||
|
||||
3. jar打包文件。jar命令在工作目录下执行。out/目录下打包所有内容。如果没有主类,则使用jar -cvf。 如果有主类则使用jar -cvfm
|
||||
|
||||
```
|
||||
➜ out git:(master) ✗ jar -cvfm hello.jar *
|
||||
已添加清单
|
||||
正在添加: com/(输入 = 0) (输出 = 0)(存储了 0%)
|
||||
正在添加: com/ykl/(输入 = 0) (输出 = 0)(存储了 0%)
|
||||
正在添加: com/ykl/MANIFEST.MF(输入 = 48) (输出 = 48)(压缩了 0%)
|
||||
正在添加: com/ykl/hello.jar(输入 = 3072) (输出 = 474)(压缩了 84%)
|
||||
正在添加: com/ykl/Main.class(输入 = 422) (输出 = 293)(压缩了 30%)
|
||||
```
|
||||
|
||||
4. 执行文件
|
||||
|
||||
```
|
||||
➜ out git:(master) ✗ java -jar hello.jar
|
||||
hello world!
|
||||
```
|
||||
|
||||
## 3 使用IDEA打包一个可执行文件
|
||||
|
||||
1. 创建一个Java工程
|
||||
|
||||
|
||||
|
||||
2. 配置artifacts,打包成jar。project structure -> artifact -> moudule import。利用IDEA自动打包过程会添加MANIFEST.MF 文件到打包文件中。
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
## 4 导入一个非maven的jar包。
|
||||
|
||||
1. 将jar包安装到maven仓库中。install
|
||||
|
||||
```java
|
||||
mvn install:install-file -Dfile=./hello.jar \
|
||||
-DgroupId=com.ykl \
|
||||
-DartifactId=java-main-project \
|
||||
-Dversion=1 \
|
||||
-Dpackaging=jar
|
||||
```
|
||||
|
||||
```
|
||||
➜ out git:(master) ✗ mvn install:install-file -Dfile=./hello.jar \
|
||||
-DgroupId=com.ykl \
|
||||
-DartifactId=java-main-project \
|
||||
-Dversion=1 \
|
||||
-Dpackaging=jar
|
||||
[INFO] Scanning for projects...
|
||||
[INFO]
|
||||
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
|
||||
[INFO] Building Maven Stub Project (No POM) 1
|
||||
[INFO] --------------------------------[ pom ]---------------------------------
|
||||
[INFO]
|
||||
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
|
||||
[INFO] Installing /Users/yinkanglong/work/notes/maven/maven源码/project04-maven-import/purejavamoudle/src/out/hello.jar to /Users/yinkanglong/.m2/repository/com/ykl/java-main-project/1/java-main-project-1.jar
|
||||
[INFO] Installing /var/folders/w5/xwpp23dd6qxfb4b8kw2512nr0000gp/T/mvninstall3747814679268417305.pom to /Users/yinkanglong/.m2/repository/com/ykl/java-main-project/1/java-main-project-1.pom
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] BUILD SUCCESS
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] Total time: 0.379 s
|
||||
[INFO] Finished at: 2022-11-07T14:07:10+08:00
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
```
|
||||
|
||||
2. 查看maven仓库中的jar包
|
||||
|
||||

|
||||
|
||||
3. 引入自定义安装的jar包
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.ykl</groupId>
|
||||
<artifactId>java-main-project</artifactId>
|
||||
<version>1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
4. 测试程序。创建这个方法,并运行成功。
|
||||
|
||||
```java
|
||||
package com.ykl;
|
||||
import com.ykl.Main;
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
Main.main( args );
|
||||
}
|
||||
}
|
||||
```
|
||||
48
maven/1简介.md
@@ -1,48 +0,0 @@
|
||||
# maven简介
|
||||
|
||||
> 纯java开源项目。**项目管理工具**,对java项目进行构建、依赖管理。也可以用于构建和管理其他项目(c#,Ruby,Scala)
|
||||
|
||||
> 在上一次做handoop mapreduce的时候,发现了pom文件,然后配置了maven,作为maven工程打开过。但是具体的过程,为啥忘得一干二净,只记得自己曾经对maven的setting文件进行修改,那个时候应该还创建了本地库。但是完全记不清了。
|
||||
|
||||
## 1 maven主要功能
|
||||
|
||||
* 构建
|
||||
* 文档生成
|
||||
* 报告
|
||||
* 依赖
|
||||
* SCMs
|
||||
* 发布
|
||||
* 分发
|
||||
* 邮件列表
|
||||
|
||||
|
||||
## 2 maven项目目录结构
|
||||
| 目录| 目的|
|
||||
|-|-|
|
||||
| ${basedir} |存放pom.xml和所有的子目录|
|
||||
| ${basedir}/src/main/java |项目的java源代码|
|
||||
| ${basedir}/src/main/resources |项目的资源,比如说property文件,springmvc.xml|
|
||||
| ${basedir}/src/test/java |项目的测试类,比如说Junit代码|
|
||||
| ${basedir}/src/test/resources |测试用的资源|
|
||||
| ${basedir}/src/main/webapp/WEB-INF |web应用文件目录,web项目的信息,比如存放web.xml、本地图片、jsp视图页面|
|
||||
| ${basedir}/target |打包输出目录|
|
||||
| ${basedir}/target/classes |编译输出目录|
|
||||
| ${basedir}/target/test-classes |测试编译输出目录|
|
||||
| Test.java |Maven只会自动运行符合该命名规则的测试类|
|
||||
| ~/.m2/repository |Maven默认的本地仓库目录位置|
|
||||
|
||||
|
||||
## 3 maven项目的优势
|
||||
* 基于模型的构建 − Maven能够将任意数量的项目构建到预定义的输出类型中,如 JAR,WAR 或基于项目元数据的分发,而不需要在大多数情况下执行任何脚本。
|
||||
* 项目信息的一致性站点 − 使用与构建过程相同的元数据,Maven 能够生成一个网站或PDF,包括您要添加的任何文档,并添加到关于项目开发状态的标准报告中。
|
||||
* 发布管理和发布单独的输出 − Maven 将不需要额外的配置,就可以与源代码管理系统(如 Subversion 或 Git)集成,并可以基于某个标签管理项目的发布。它也可以将其发布到分发位置供其他项目使用。Maven 能够发布单独的输出,如 JAR,包含其他依赖和文档的归档,或者作为源代码发布。
|
||||
* 向后兼容性 − 您可以很轻松的从旧版本 Maven 的多个模块移植到 Maven 3 中。
|
||||
* 子项目使用父项目依赖时,正常情况子项目应该继承父项目依赖,无需使用版本号
|
||||
* 并行构建 − 编译的速度能普遍提高20 - 50 %。
|
||||
* 更好的错误报告 − Maven 改进了错误报告,它为您提供了 Maven wiki 页面的链接,您可以点击链接查看错误的完整描述。
|
||||
|
||||
## 4 maven名词解释
|
||||
* 项目对象模型POM:,xml文件,项目基本信息,描述项目构建过程,声明项目依赖。
|
||||
* 构件:任何一个依赖、插件或者项目构建输出,都可以称之为构件。
|
||||
* 插件Plugin:maven是依赖插件完成任务的,项目管理工具。
|
||||
* 仓库Repository:maven仓库能够帮我们管理构件
|
||||
@@ -1,64 +0,0 @@
|
||||
## 1 简介
|
||||
|
||||
maven项目包含三个生命周期,每个生命周期包含多个节点。每个节点都是由maven插件实现。例如maven-clean-plugin
|
||||
|
||||
maven实际上是一个依赖插件执行的框架。
|
||||
|
||||
插件提供了一个目标的集合。使用以下语法执行
|
||||
```
|
||||
mvn [plugin-name]:[goal-name]
|
||||
mvn compiler:compile
|
||||
```
|
||||
|
||||
## 2 常用插件
|
||||
|
||||
分为两类
|
||||
* Build plugins
|
||||
* Repoting plugins
|
||||
|
||||
常用插件列表
|
||||
|
||||
* clean 构建之后清理目标文件。删除目标目录。
|
||||
* compiler 编译 Java 源文件。
|
||||
* surefile 运行 JUnit 单元测试。创建测试报告。
|
||||
* jar 从当前工程中构建 JAR 文件。
|
||||
* war 从当前工程中构建 WAR 文件。
|
||||
* javadoc 为工程生成 Javadoc。
|
||||
* antrun 从构建过程的任意一个阶段中运行一个 ant 任务的集合。
|
||||
|
||||
## 3 插件修改方法
|
||||
|
||||
```
|
||||
<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.companyname.projectgroup</groupId>
|
||||
<artifactId>project</artifactId>
|
||||
<version>1.0</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>id.clean</id>
|
||||
<phase>clean</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<echo>clean phase</echo>
|
||||
</tasks>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
```
|
||||
@@ -1,19 +0,0 @@
|
||||
## 1. 引入外部依赖到项目中
|
||||
在src下创建lib文件夹,用来防止第三方的jar文件。
|
||||
```
|
||||
<dependencies>
|
||||
<!-- 在这里添加你的依赖 -->
|
||||
<dependency>
|
||||
<groupId>ldapjdk</groupId> <!-- 库名称,也可以自定义 -->
|
||||
<artifactId>ldapjdk</artifactId> <!--库名称,也可以自定义-->
|
||||
<version>1.0</version> <!--版本号-->
|
||||
<scope>system</scope> <!--作用域-->
|
||||
<systemPath>${basedir}\src\lib\ldapjdk.jar</systemPath> <!--项目根目录下的lib文件夹下-->
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
|
||||
## 2. 引入外部依赖到本地中
|
||||
|
||||
可以直接下载到当前的mvn本地仓库中。.m2/repository
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
用于快速的模块化的版本迭代。
|
||||
|
Before Width: | Height: | Size: 303 KiB After Width: | Height: | Size: 303 KiB |
|
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 47 KiB |
|
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 427 KiB After Width: | Height: | Size: 427 KiB |
|
Before Width: | Height: | Size: 494 KiB After Width: | Height: | Size: 494 KiB |
|
Before Width: | Height: | Size: 110 KiB After Width: | Height: | Size: 110 KiB |
|
Before Width: | Height: | Size: 327 KiB After Width: | Height: | Size: 327 KiB |
|
Before Width: | Height: | Size: 560 KiB After Width: | Height: | Size: 560 KiB |
|
Before Width: | Height: | Size: 632 KiB After Width: | Height: | Size: 632 KiB |
|
Before Width: | Height: | Size: 108 KiB After Width: | Height: | Size: 108 KiB |
BIN
maven/image/2022-11-03-09-40-26.png
Normal file
|
After Width: | Height: | Size: 266 KiB |
BIN
maven/image/2022-11-05-21-14-18.png
Normal file
|
After Width: | Height: | Size: 377 KiB |
BIN
maven/image/2022-11-05-21-47-56.png
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
maven/image/2022-11-05-22-27-12.png
Normal file
|
After Width: | Height: | Size: 634 KiB |
BIN
maven/image/2022-11-05-23-03-56.png
Normal file
|
After Width: | Height: | Size: 398 KiB |
BIN
maven/image/2022-11-06-10-09-40.png
Normal file
|
After Width: | Height: | Size: 457 KiB |
BIN
maven/image/2022-11-06-10-10-36.png
Normal file
|
After Width: | Height: | Size: 518 KiB |
BIN
maven/image/2022-11-06-10-11-01.png
Normal file
|
After Width: | Height: | Size: 267 KiB |
BIN
maven/image/2022-11-06-10-11-48.png
Normal file
|
After Width: | Height: | Size: 452 KiB |
BIN
maven/image/2022-11-06-10-15-28.png
Normal file
|
After Width: | Height: | Size: 327 KiB |
BIN
maven/image/2022-11-06-10-41-09.png
Normal file
|
After Width: | Height: | Size: 361 KiB |
BIN
maven/image/2022-11-06-21-59-58.png
Normal file
|
After Width: | Height: | Size: 727 KiB |
BIN
maven/image/2022-11-06-22-19-48.png
Normal file
|
After Width: | Height: | Size: 365 KiB |
BIN
maven/image/2022-11-06-22-24-53.png
Normal file
|
After Width: | Height: | Size: 215 KiB |
BIN
maven/image/2022-11-06-22-25-13.png
Normal file
|
After Width: | Height: | Size: 237 KiB |
BIN
maven/image/2022-11-06-22-30-18.png
Normal file
|
After Width: | Height: | Size: 183 KiB |
BIN
maven/image/2022-11-06-22-31-10.png
Normal file
|
After Width: | Height: | Size: 182 KiB |
BIN
maven/image/2022-11-06-22-34-11.png
Normal file
|
After Width: | Height: | Size: 531 KiB |
BIN
maven/image/2022-11-06-22-41-34.png
Normal file
|
After Width: | Height: | Size: 371 KiB |
BIN
maven/image/2022-11-06-23-16-13.png
Normal file
|
After Width: | Height: | Size: 335 KiB |
BIN
maven/image/2022-11-07-09-44-42.png
Normal file
|
After Width: | Height: | Size: 250 KiB |
BIN
maven/image/2022-11-07-09-44-57.png
Normal file
|
After Width: | Height: | Size: 498 KiB |
BIN
maven/image/2022-11-07-09-46-05.png
Normal file
|
After Width: | Height: | Size: 518 KiB |
BIN
maven/image/2022-11-07-09-54-26.png
Normal file
|
After Width: | Height: | Size: 431 KiB |
BIN
maven/image/2022-11-07-13-27-00.png
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
maven/image/2022-11-07-13-27-10.png
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
maven/image/2022-11-07-14-13-21.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
maven/image/2022-11-07-14-20-24.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
maven/image/2022-11-07-14-20-41.png
Normal file
|
After Width: | Height: | Size: 212 KiB |
BIN
maven/image/2022-11-07-14-27-22.png
Normal file
|
After Width: | Height: | Size: 139 KiB |
BIN
maven/image/2022-11-07-14-48-13.png
Normal file
|
After Width: | Height: | Size: 8.7 KiB |
BIN
maven/image/2022-11-07-14-56-43.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
maven/image/2022-11-07-15-01-29.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
maven/image/2022-11-07-15-01-40.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
maven/image/2022-11-07-15-01-48.png
Normal file
|
After Width: | Height: | Size: 29 KiB |
BIN
maven/image/2022-11-07-15-17-31.png
Normal file
|
After Width: | Height: | Size: 238 KiB |
BIN
maven/image/images.png
Normal file
|
After Width: | Height: | Size: 42 KiB |
@@ -1,6 +0,0 @@
|
||||
# maven工作机制
|
||||
|
||||
|
||||
## 1 工作机制
|
||||
|
||||

|
||||
@@ -1,21 +0,0 @@
|
||||
## 1 命令
|
||||
|
||||
|
||||
### 基本命令
|
||||
|
||||
* 主命令
|
||||
* 插件
|
||||
* 子命令
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
### 生成maven工程
|
||||
|
||||
```
|
||||
mvn archetype:generate -DarchetypeGroupId=com.alipay.sofa -DarchetypeArtifactId=sofaboot-web-archetype -DarchetypeVersion=1.0-SNAPSHOT -DarchetypeCatalog=internal
|
||||
```
|
||||
|
||||
## 2 pom解析
|
||||
|
||||
@@ -32,6 +32,11 @@
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>4.0.0.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.ykl;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
@@ -9,5 +12,13 @@ public class App
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
Properties properties = System.getProperties();
|
||||
|
||||
Set<Object> properitesSet = properties.keySet();
|
||||
|
||||
for (Object propName :properitesSet){
|
||||
String propValue = properties.getProperty((String)propName);
|
||||
System.out.println(propName + ": " + propValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.ykl</groupId>
|
||||
<artifactId>project02-maven-web</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>0.0.1-snapshot</version>
|
||||
|
||||
<packaging>war</packaging>
|
||||
<name>project02-maven-web Maven Webapp</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
@@ -14,14 +17,25 @@
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
|
||||
<!-- 为了能够导入httpservlet会导入依赖 -->
|
||||
<dependency>
|
||||
<!-- 通过被指定工程的坐标完成依赖 -->
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ykl</groupId>
|
||||
<artifactId>project01-maven-java</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.ykl;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
{
|
||||
/**
|
||||
* Rigorous Test :-)
|
||||
*/
|
||||
@Test
|
||||
public void shouldAnswerWithTrue()
|
||||
{
|
||||
assertTrue( true );
|
||||
System.out.println("test finish");
|
||||
}
|
||||
}
|
||||
25268
maven/maven源码/project03-maven-test/effective-pom.xml
Normal file
68
maven/maven源码/project03-maven-test/pom.xml
Normal file
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>2.6.2</version>
|
||||
</parent>
|
||||
<groupId>com.ykl</groupId>
|
||||
<artifactId>project03-maven-test</artifactId>
|
||||
<version>0.0.1-snapshot</version>
|
||||
|
||||
<!-- 打包方式改为pom表示是一个parent工程 -->
|
||||
<packaging>pom</packaging>
|
||||
<name>project03-maven-test</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<!-- 聚合的配置 -->
|
||||
<modules>
|
||||
<module>project04-maven-moduele</module>
|
||||
<module>project05-maven-moduele</module>
|
||||
<module>project06-maven-moduele</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<com.ykl.hello>temp</com.ykl.hello>
|
||||
<com.ykl.world>world</com.ykl.world>
|
||||
</properties>
|
||||
<!-- 在付工程中统一管理依赖信息 -->
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spingframwork</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>4.0.0.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
<version>4.0.0.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<groupId>org.springframework</groupId>
|
||||
<version>4.0.0.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-expression</artifactId>
|
||||
<version>4.0.0.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aop</artifactId>
|
||||
<version>4.0.0.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<!-- 通过指定parent标签指定父工程,一般子工程不需要groupedId和version -->
|
||||
<parent>
|
||||
<groupId>com.ykl</groupId>
|
||||
<artifactId>project03-maven-test</artifactId>
|
||||
<version>0.0.1-snapshot</version>
|
||||
</parent>
|
||||
<groupId>com.ykl</groupId>
|
||||
<artifactId>project04-maven-moduele</artifactId>
|
||||
<version>0.0.1-snapshot</version>
|
||||
<name>project04-maven-moduele</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.ykl;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.ykl;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
extends TestCase
|
||||
{
|
||||
/**
|
||||
* Create the test case
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public AppTest( String testName )
|
||||
{
|
||||
super( testName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
return new TestSuite( AppTest.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
public void testApp()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.ykl</groupId>
|
||||
<artifactId>project03-maven-test</artifactId>
|
||||
<version>0.0.1-snapshot</version>
|
||||
</parent>
|
||||
<groupId>com.ykl</groupId>
|
||||
<artifactId>project05-maven-moduele</artifactId>
|
||||
<version>0.0.1-snapshot</version>
|
||||
<name>project05-maven-moduele</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.ykl;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.ykl;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
extends TestCase
|
||||
{
|
||||
/**
|
||||
* Create the test case
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public AppTest( String testName )
|
||||
{
|
||||
super( testName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
return new TestSuite( AppTest.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
public void testApp()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.ykl</groupId>
|
||||
<artifactId>project03-maven-test</artifactId>
|
||||
<version>0.0.1-snapshot</version>
|
||||
</parent>
|
||||
<groupId>com.ykl</groupId>
|
||||
<artifactId>project06-maven-moduele</artifactId>
|
||||
<version>0.0.1-snapshot</version>
|
||||
<name>project06-maven-moduele</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-expression</artifactId>
|
||||
<version>4.0.0.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aop</artifactId>
|
||||
<version>4.0.0.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.ykl;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.ykl;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
extends TestCase
|
||||
{
|
||||
/**
|
||||
* Create the test case
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public AppTest( String testName )
|
||||
{
|
||||
super( testName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
return new TestSuite( AppTest.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
public void testApp()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.ykl;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.ykl;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
extends TestCase
|
||||
{
|
||||
/**
|
||||
* Create the test case
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public AppTest( String testName )
|
||||
{
|
||||
super( testName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
return new TestSuite( AppTest.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
public void testApp()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
23
maven/maven源码/project04-maven-import/pom.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.ykl</groupId>
|
||||
<artifactId>project04-maven-import</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.0.1-snapshot</version>
|
||||
<name>project04-maven-import</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ykl</groupId>
|
||||
<artifactId>java-main-project</artifactId>
|
||||
<version>1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.ykl;
|
||||
public class Main{
|
||||
public static void main(String[] args){
|
||||
System.out.println("hello world!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: com.ykl.Main
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: com.ykl.Main
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.ykl;
|
||||
import com.ykl.Main;
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
Main.main( args );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.ykl;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
extends TestCase
|
||||
{
|
||||
/**
|
||||
* Create the test case
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public AppTest( String testName )
|
||||
{
|
||||
super( testName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
return new TestSuite( AppTest.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
public void testApp()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="project05-maven-plugin" />
|
||||
<module name="hello-maven-plugin" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
|
||||
30
maven/maven源码/project05-maven-plugin/pom.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.ykl</groupId>
|
||||
<artifactId>hello-maven-plugin</artifactId>
|
||||
<version>0.0.1-snapshot</version>
|
||||
|
||||
<packaging>maven-plugin</packaging>
|
||||
<name>hello-maven-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>3.5.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||
<artifactId>maven-plugin-annotations</artifactId>
|
||||
<version>3.5.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.ykl;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.ykl;
|
||||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
|
||||
/**
|
||||
* @goal sayhello
|
||||
*/
|
||||
//@Mojo(name = "sayhello2")
|
||||
public class MyPlugin extends AbstractMojo {
|
||||
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
getLog().info("---> This is my first maven plugin. <---");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.ykl;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
extends TestCase
|
||||
{
|
||||
/**
|
||||
* Create the test case
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public AppTest( String testName )
|
||||
{
|
||||
super( testName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
return new TestSuite( AppTest.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
public void testApp()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||