maven 是 Apache 的一个项目管理软件,解决项目的依赖关系 pom.xml
下载地址:http://mirrors.hust.edu.cn/apache/maven/maven-3/3.3.9/binaries/
一、maven 安装
1.解压后移动到 /soft 目录下:
tar -xzvf xxx.gz
2.创建符号链接
3.配置环境变量:
$ sudo nano /etc/environment
M2_HOME=/soft/maven
PATH="/soft/maven/bin"
4.立刻生效:
$ source /etc/environment
5.查看 maven 版本:
$ mvn -verson
6.进入 maven 的配置目录:/soft/maven/conf
7.配置 conf 下的 settings.xml 文件:
<?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">
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
</servers>
<mirrors>
<mirror>
<id>nexus-osc</id>
<mirrorOf>central</mirrorOf>
<name>Nexus osc</name>
<url>http://maven.oschina.net/content/groups/public</url>
</mirror>
<mirror>
<id>nexus-osc-thirdparty</id>
<mirrorOf>thirdparty</mirrorOf>
<name>Nexus osc thirdparty</name>
<url>http://maven.oschina.net/content/reposi tories/thirdpart</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>jdk-1.7</id>
<activation>
<jdk>1.7</jdk>
</activation>
<repositories>
<repository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://maven.oschina.net/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginrepositories>
<pluginrepository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://maven.oschina.net/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginrepository>
</pluginrepositories>
</profile>
</profiles>
</settings>
8.maven 仓库本地存放位置默认为:
${user.home}./m2/
可修改本地仓库存放路径
[conf/settings.xml]
<localRepository>/path/to/local/repo</localRepository>
二、maven 本地仓库搭建
由于多台机器同时访问 maven 的外网仓库会导致网络拥堵,所以可以在一台机器上搭建 maven 本地仓库,其余机器访问该机器。
1.下载所需软件:
JDK 1.6+,Tomcat,Nexus.war(Tomcat9 适合 JDK1.8 ,Tomcat8 适合 JDK1.9)
2.安装 Tomcat:
$ cp /mnt/hgfs/share\ for\ linux/apache-tomcat-9.0.12.tar.gz ~/Downloads/
$ cp /mnt/hgfs/share\ for\ linux/nexus-2.14.5-02.war ~/Downloads/
$ tar -xzvf apache-tomcat-9.0.12
$ sudo mv apache-tomcat-9.0.12 /soft
$ sudo ln -s apache-tomcat-9.0.12/ tomcat
3.移动 Nexus.war 到 Tomcat 安装目录下的 webapps :
$ mv merge.txt /soft/tomcat/webapps/
4.启动 Tomcat:
$ /soft/tomcat/bin/startup.sh
因为没有配置环境变量所以启动时要全路径
5.查看是否启动成功:
进入 web 页面 :ubuntucp:8080
在这里把 maven 本地仓库放在宿主机(Windows)上:
1.下载所需软件:
JDK 1.6+,Tomcat,Nexus.war (Tomcat9 适合 JDK1.8 ,Tomcat8 适合 JDK1.9)
2.移动 Nexus.war 到 Tomcat 安装目录下的 webapps
3.打开 Tomcat 下的 bin 目录中的 startup.bat
4.浏览器输入 localhost:8080/ 和 localhost:8080/nexus 查看
5.修改默认仓库目录:
进入E:\software\apache-tomcat-9.0.12\webapps\nexus\WEB-INF\classes,修改 nexus.properties
改为 nexus-work=e:/software/maven/nexus
6.配置 maven 使用本地仓库服务器:
在 ubuntu 中,进入 /soft/maven/conf/settings.xml,将所有 maven.oschina.net 改为 192.168.75.1:8080(宿主机IP)