

注:IDEA新版的直接自带Maven版本,用自带的也比较好。不然配置繁琐。
MVN
仓库:用于储存 Jar 包,供给 Java 项目使用。
仓库分类:
本地仓库:自己电脑上存储资源的仓库,连接远程仓库获取资源
远程仓库:非本机电脑上的仓库,为本地仓库提供资源
中央仓库:Mavenl团队维护,存储所有资源的仓库(https://repo1.maven.org/maven2/)
私服:部门/公司范围内存储资源的仓库,从中央仓库获取资源
私服的作用:

Maven,启动后,会自动保存下载的资源到本地仓库
< --! 默认位置>
<localRepository>${user.home}/.m2/repositorylocalRepository>
当前目录位置为登录用户名所在目录下的.m2文件夹中
<--! 自定义位置>
<localRepository>D:\maven\repositorylocalRepository>
当前目录位置为D:maven repository.文件夹中
<repositories>
<repository>
<id>centralid>
<name>Central Repositoryname>
<url>https://repo.maven.apache.org/maven2url>
<layout>defaultlayout>
<snapshots>
<enabled>falseenabled>
snapshots>
repository>
repositories>
<mirrors>
<mirror>
<id>nexus-aliyunid>
<mirrorOf>centralmirrorOf>
<name>Nexus aliyunname>
<url>http://maven.aliyun.com/nexus/content/groups/publicurl>
mirror>
mirrors>
groupld(组织ID):定义当前Maven项目隶属组织名称(通常是域名反写,例如:org.mybatis)
artifactld(项目ID):定义当前Maven项目名称(通常是模块名称,例如CRM、SMS)
version(版本号):定义当前项目版本号
packaging:定义该项目的打包方式

<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.0modelVersion>
<groupId>org.examplegroupId>
<artifactId>untitledartifactId>
<version>1.0-SNAPSHOTversion>
<packaging>jarpackaging>
<name>untitledname>
<url>http://maven.apache.orgurl>
<properties>
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
properties>
<dependencies>
<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
<version>3.8.1version>
<scope>testscope>
dependency>
dependencies>
project>

<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.mavengroupId>
<artifactId>tomcat7-maven-pluginartifactId>
<version>2.1version>
<configuration>
<port>80port>
<path>/path>
configuration>
plugin>
plugins>
build>
<dependencies>
<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
<version>4.12version>
dependency>
dependencies>
– SNAPSHOT:开发版本,表示该版本仍在开发中,可能会频繁改变。
– RELEASE:发布版本,表示该版本为稳定版本,很少改变。(非SNAPSHOT的就是RELEASE)
– ALPHA:内部测试版本,一般不供外部使用。
– BETA:公开测试版本,可供外部测试并提供反馈。

<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
<version>4.12version>
<optional>trueoptional>
dependency>
<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
<version>4.12version>
<exclusions>
<exclusion>
<groupId>org.hamcrestgroupId>
<artifactId>hamcrest-coreartifactId>
exclusion>
exclusions>
dependency>
<scope>compilescope>



<build>
<plugins>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-source-pluginartifactId>
<version>2.2.1version>
<executions>
<execution>
<goals>
<goal>jargoal>
<goal>test-jargoal>
goals>
<phase>generate-test-resourcesphase>
execution>
executions>
plugin>
plugins>
build>