Maven中的依赖是从服务器仓库中下载的,Maven的仓库只有两大类:java
Maven用户直接链接远程仓库下载构件的作法是Maven不建议使用的(尤为是对一个开发团队来讲),Maven的最佳实践就是使用Maven私服来构建整个团队的项目部署和管理。私服是一种特殊的远程仓库,它是架设在局域网内的仓库服务,私服代理广域网上的远程仓库,供局域网内的Maven用户使用。当Maven须要下载构件的时候,它从私服请求,若是私服上不存在该构件,则从外部的远程仓库下载,缓存在私服上以后,再为Maven的下载请求提供服务。web
构建Maven私服使用Nexus,Nexus是一个强大的Maven仓库管理器,它极大地简化了本身内部仓库的维护和外部仓库的访问。利用Nexus你能够只在一个地方就可以彻底控制访问 和部署在你所维护仓库中的每一个Artifact。Nexus是一套“开箱即用”的系统不须要数据库,它使用文件系统加Lucene来组织数据。Nexus 使用ExtJS来开发界面,利用Restlet来提供完整的REST APIs,经过m2eclipse与Eclipse集成使用。Nexus支持WebDAV与LDAP安全身份认证。spring
说完了私服的好处,你是否是已经等不及开始构建你的maven私服了,那么咱们开始一块儿构建咱们的私服。首先进入Nexus的网站http://www.sonatype.org/nexus/go/,找到你须要的包,下载(演示在CentOS上安装):docker
若是你但愿用一些历史版本的包,https://help.sonatype.com/repomanager3/download/download-archives---repository-manager-3,里面自行查找。首先下载对应的包到服务器上:数据库
mkdir tools #新建tools目录
cd tools # 进入tools目录
wget http://download.sonatype.com/nexus/3/nexus-3.14.0-04-unix.tar.gz # 下载对应的安装包
tar zxvf nexus-3.14.0-04-unix.tar.gz # 解压缩
mv nexus-3.14.0-04/ /usr/local/nexus
cd /usr/local/nexus/bin复制代码
安装java运行环境:apache
yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel复制代码
修改nexus.rc,让root能够启动nexus,nexus.rc在/usr/local/nexus/bin/下:vim
vim nexus.rc,删除run_as_user前面的注释,后面加上root:run_as_user=root复制代码
而后按esc按键,输入:wq回车。而后启动nexus缓存
./nexus run &复制代码
出现以下内容,表示启动成功安全
经过http://localhost:8081就能够访问了。服务器
首先:前往maven中央仓库下载 indexer-cli-5.1.1.jar解压工具
其次下载:nexus-maven-repository-index.properties和nexus-maven-repository-index.gz
再次,将上面下载的3个文件放到同一个路径下,经过以下命令解压:
java -jar indexer-cli-5.1.1.jar -u nexus-maven-repository-index.gz -d indexer复制代码
最后,拷贝索引
nexus3.x拷贝到/sonatype-work/nexus3/blobs/default,3.x
复制代码
首先访问对应的地址,而后输入默认用户名 admin、密码 admin123:
点击左侧的browse,能够看到各类repository的type,那么这些类型有什么区别呢:
进入设置页面
做以下操做:
在maven的setting.xml文件中配置私服配置,这种方式配置后全部本地使用该配置的maven项目的pom文件都无需配置私服下载相关配置(下文中192.179.101.1:8081须要替为你本身的)
<?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">
复制代码
<servers>
<server>
<id>nexus-releases</id>
<username>deployment</username>
<password>deployment123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>deployment</username>
<password>deployment123</password>
</server>
</servers>复制代码
<mirrors>复制代码
<mirror>
<id>nexus-releases</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.101.1:8081/content/groups/public/</url>
<!-- <url>http://repo1.maven.org/maven2/</url> -->
</mirror>
<mirror>
<id>nexus-snapshots</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.101.1:8081/content/repositories/snapshots/</url>
<!-- <url>http://repo1.maven.org/maven2/</url> -->
</mirror>复制代码
</mirrors>复制代码
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus-releases</id>
<url>http://192.168.101.1:8081/content/groups/public/</url>
<!-- <url>http://repo1.maven.org/maven2/</url> -->
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>nexus-snapshots</id>
<url>http://192.168.101.1:8081/content/repositories/snapshots/</url>
<!-- <url>http://repo1.maven.org/maven2/</url> -->
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-releases</id>
<url>http://192.168.101.1:8081/content/groups/public/</url>
<!-- <url>http://repo1.maven.org/maven2/</url> -->
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus-snapshots</id>
<url>http://192.168.101.1:8081/content/repositories/snapshots/</url>
<!-- <url>http://repo1.maven.org/maven2/</url> -->
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>复制代码
<activeProfiles>
<activeProfile>nexus</activeProfile>
<!--<activeProfile>dev</activeProfile>-->
</activeProfiles>复制代码
</settings>复制代码
docker确实是个好东西,快速,方便,使用docker部署Nexus那就是几分钟的事情具体以下命令:
docker pull sonatype/nexus3
docker run -d -p 8081:8081 --name nexus sonatype/nexus3复制代码
启动完成后,方位http://localhost:8081就能够进入web页面了,其余操做和配置和上面的内容一致,所以这部分就不在这里描述了。关注我,关注测试FROM:https://blog.csdn.net/crisschan