Nexus是典型的java web应用,它有两种安装包,一种是包含jetty容器的Bundle包,另一种是不包含web容器的war包。
本文用的nexus版本为2.5
用的服务器为linux
解压后,进入目录 ./bin/jsw/linux-x86-32(我的机器是32位)
然后运行./nexus console
意思是用控制台启动,也可以认为是前台启动。注意,不能用root账户启动。
其他的几个也命令也需要了解一下
./nexus start: 后台启动
./nexus stop:停止服务
./nexus status :查看后台状态
./nexus restart:重新启动nexus服务
nexus的默认管理员登录用户/密码:admin/admin123
=============================================
在使用nexus之前,先来了解一点nexus内置的仓库
建议使用nexus 的group类型的库,具体是本来就有的Public Repositorites。这个库是个组合库,不是一个真实的库,其中包含4个库(都是内置库),maven中央仓库的代理库,自己的版本和快照宿主库,还有一个第三方库。这个组合库是公开的,不需要用户名密码
配置maven的settings.xml
首先,要把私服设为镜像,这样所有的请求都会走私服。
<mirrors>
<mirror>
<id>nexus-mirror</id>
<name>nexus mirror</name>
<url>http://hadoop1:8081/nexus/content/groups/public/</url>
<!--*表示是所有的仓库的镜像,也就是说所有的仓库请求都要走这个镜像-->
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<!--配置仓库
仓库及插件库配置。也许有人会说,不是当使用nexus私服镜像了吗,为啥还要再进行其他仓库的配置呢
答案是开始对版本,快照下载的支持
当maven需要下载的时候,先检验central,看该类型的jar包是否支持,得到正确的回答后,在根据镜像
匹配规则转而访问私服地址。所以下面的url标签是没哟意义的,随便写就行了。
-->
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<name>maven central repository</name>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</profiles>
=====================================
以上是配置读操作,也就是从仓库组中读。如果发布自己的项目,就是写操作。
如果发布项目,可以用命令mvn clean deploy
nexus的仓库对于匿名用户来说是只读的,所以要想发布项目(写),那么就需要身份认证。
在settings.xml中如下配置
<servers>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
还需要在pom文件中指定要写入的库
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>nexus releases repository </name>
<url>http://hadoop1:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>nexus snapshots repository </name>
<url>http://hadoop1:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
至此,就完成了。