世界上任何一个构件都可以使用Maven坐标唯一标识
pom.xml和settings.xml是maven中重要的两个配置文件
1.pom.xml
<?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> //pom版本模型(maven2/3只能为4.0.0)
//基本配置
<groupId>com.example</groupId> //组ID,用于定位
<artifactId>mavendemo02</artifactId> //组中唯一ID用于定位
<version>1.0-SNAPSHOT</version> //项目版本
<packaging>war</packaging> //项目打包方式
//项目信息
<name>mavendemo02 Maven Webapp</name> //项目名
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url> // 主页url
//用于定义pom常量
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
//依赖配置
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
//构建配置
<build>
<finalName>mavendemo02</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
//使用插件列表
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
2.settings.xml
settings.xml里面是Maven的基本配置
全局级别
用户级别
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
//用于构建系统的本地仓库的路径
<localRepository>
D:\Program Files (x86)\apache-maven-3.5.3-bin\maven-repository
</localRepository>
//插件组
<pluginGroups>
<pluginGroup>com.your.plugins</pluginGroup>
</pluginGroups>
//设置http代理
<proxies>
<proxy>
<id>optional</id>//proxy唯一标识
<active>true</active>//表示是否激活代理,如果配置多个,默认是第一个生效
<protocol>http</protocol>
<username>proxyuser</username>
// 供连接代理服务器时的认证
<password>proxypass</password>
<host>proxy.host.net</host>//主机地址
<port>80</port>//端口号
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
//用来表示哪些主机名不需要代理,可以用|来分割多个,此外也支持通配符
</proxy>
</proxies>
//认证配置,在maven连接到远程服务时使用
<servers>
//使用登录方式认证
<server>
<id>deploymentRepo</id>
<username>repouser</username>
<password>repopwd</password>
</server>
//使用密钥认证
<server>
<id>siteServer</id>
<privateKey>/path/to/private/key</privateKey>
<passphrase>optional; leave empty if not used.</passphrase>
</server>
</servers>
//指定镜像仓库位置,用于从远程仓库下载资源
<mirrors>
<mirror>
<id>mirrorId</id>//唯一
<mirrorOf>repositoryId</mirrorOf>//镜像所包含的仓库id
<name>Human Readable Name for this Mirror.</name>//唯一标识,用于区分镜像站
<url>http://my.repository.com/repo/path</url>//镜像路径
</mirror>
</mirrors>
//定义一系列的配置信息,然后指定其激活条件
<profiles>
<profile>
<id>jdk-1.4</id>
<activation>
<jdk>1.4</jdk>
</activation>
//Repositories是远程项目集合maven用来移植到本地仓库用于构建系统。如果来自本地仓库, Maven调用它的插件和依赖关系。不同的远程仓库可能包含不同的项目,当profile被激活,他们 就会需找匹配的release或者snapshot构件。
<repositories>
<repository>
<id>jdk14</id>
<name>Repository for JDK 1.4 builds</name>
<url>http://www.myhost.com/maven/jdk14</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</repository>
</repositories>
</profile>
<profile>
<id>env-dev</id>
//
<activation>
<property>//当maven检测到property(pom中如${name}这样的)profile将被激活
<name>target-env</name>
<value>dev</value>
</property>
</activation>
//Maven的属性是值占位符,就像Ant中的一样。如果X是一个属性的话,在POM中可以使用${X}来进行任意地方的访问。他们来自于五种不同的风格,所有都可以从settings.xml文件中访问到。
<properties>
<tomcatPath>/path/to/tomcat/instance</tomcatPath>
</properties>
</profile>
</profiles>
<activeProfiles>
//每个activeProfile元素对应一个profile id的值,
任何profile id被定义到activeProfile的profile将被激活。
<activeProfile>alwaysActiveProfile</activeProfile>
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
</activeProfiles>
</settings>