以window系统为例进行讲解:
一、安装mave
1、下载mave压缩包,并解压;下载地址:http://maven.apache.org/download.cgi
2、添加系统环境变量,名称:MAVE_HOME 内容为:mave解压后的地址如 D:\JavaApps\apache-maven-3.3.9
注意,解压后的路径不要带有中文字符!
3、设置系统环境变量Path,追加 %MAVE_HOME%\bin (此处不明白的自行百度。)
4、打开cmd,执行 mvn -v,有输出mave的相关信息,则安装成功。
二、mave简单设置说明。
mave需要设置远程仓库地址和本地仓库地址,目前大部分公司都会部署自己的mave私服,因此远程仓库地址需配置公司的私服地址,其次配置阿里的代理仓库地址,最后则使用默认的中央仓库地址;本地仓库地址默认是再系统盘中,建议修改该配置。
1、配置文件在conf中,如:D:\JavaApps\apache-maven-3.3.9\conf 。
2、配置文件为settings.xml。
3、找到 localRepository 标签,并填写本地仓库地址如下:
<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
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository -->
<localRepository>d:\mvn</localRepository>
4、找到 mirror 标签,并填写 公司私服地址如:
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>nexus</id>
<mirrorOf>central</mirrorOf>
<url>http://192.168.2.144:8081/nexus/content/groups/public/</url>
</mirror>
</mirrors>
5、如果需要使用 deploy 命令打包到私服(此处为nexus搭建的私服,用户名为:myuser,密码为:123456),需做如下配置:
<servers>
<!-- server
| Specifies the authentication information to use when connecting to a particular server, identified by
| a unique name within the system (referred to by the 'id' attribute below).
|
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
| used together.
|
<server>
<id>deploymentRepo</id>
<username>repouser</username>
<password>repopwd</password>
</server>
-->
<!-- Another sample, using keys to authenticate.
<server>
<id>siteServer</id>
<privateKey>/path/to/private/key</privateKey>
<passphrase>optional; leave empty if not used.</passphrase>
</server>
-->
<server>
<id>my-nexus-releases</id>
<username>myuser</username>
<password>123456</password>
</server>
<server>
<id>my-nexus-snapshots</id>
<username>myuser</username>
<password>123456</password>
</server>
</servers>
且具体项目的pom文件需做配置:
<distributionManagement>
<snapshotRepository>
<id>snapshots</id>
<name>maven-snapshots</name>
<url>http://192.168.2.144:8081/nexus/context/repository/snapshots/</url>
</snapshotRepository>
</distributionManagement>
6、其余配置内容和说明,请自行查看文档注释,以及相关资料。