Maven
·
Maven
什么是Maven
Maven是一个项目架构管理的工具
下载、安装、配置
- https://maven.apache.org/download.cgi

- 配置环境变量
- 添加 M2_HOME:D:\Program Files\apache-maven-3.6.1\bin
- 添加 MAVEN_HOME:D:\Program Files\apache-maven-3.6.1
- 为Path添加一个新变量:%MAVEN_HOME%\bin - 测试Maven是否配置成功

- 修改D:\Program Files\apache-maven-3.6.1\conf\settings.xml
- 找到<mirrrors></mirrrors>标签
- 在其标签内添加以下代码(阿里云镜像)
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*,!jeecg,!jeecg-snapshots</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
- 建立本地仓库
- 查找 localRepository添加以下代码
<localRepository>D:\Program Files\apache-maven-3.6.1\maven-repo</localRepository>
创建使用Maven




创建成功后,页面右下角会出现此通知。



pom.xml
是maven的核心配置文件
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.indi</groupId>
<artifactId>maven</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- 具体依赖的jar包配置文件,可以去maven线上仓库找,maven会帮你导入使用jar的所有依赖jar -->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<!--在build中配置resources,防止资源导出失败。-->
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/*.properties</exclude>
<exclude>**/*.xml</exclude>
</excludes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
DependncyManagement与Dependencies的区别
- Maven 使用<DependencyManagement>元素来提供了一种管理依赖版本号的方式。
- 使用pom.xml中的<DependencyManagement>元素,能让所有子项目在导入与父pom相同版本的依赖时,省去版本号的设置,直接使用父pom的版本。
- <DependencyManagement>只负责声明依赖,并不负责引入,真正引入还是要靠子项目中的<Dependency>
- 如果子项目的pom显式的指定了版本号,则以子项目的pom为准
- <Dependency>只是继承<DependencyManagement>中的版本号,不是继承依赖
- <Dependencies>管理着所有的<Dependency>
Maven中跳过单元测试

更多推荐



所有评论(0)