主要是参考里下面到帖子。在此感谢作者。
持续集成之路——搭建Maven私服
Maven仓库管理-Nexus(转帖后加强版)
nexus的安装
1.nexus的下载地址
http://nexus.sonatype.org/downloads/
我下载的是 nexus-oss-webapp-1.8.0-bundle.tar.gz
解压后得到2个文件:nexus-oss-webapp-1.8.0 和 sonatype-work
前者包含了nexus的运行环境和应用程序,后者包含了你自己的配置和数据。
2.启动nexus
在上面提到,nexus的运行环境在nexus-oss-webapp-1.8.0目录,下面就进入这个目录启动:
# cd nexus-oss-webapp-1.8.0/bin/jsw/linux-x86-32/
在这个目录下包含了一个文件夹和三个文件:lib、nexus、platform和wrapper,其中nexus就是启动命令。
执行
# ./nexus
得到nexus到提示命令 如 start,stop,status,restart 等。
输入
# ./nexus start
终端出现
Starting Nexus OSS... Started Nexus OSS
说明nexus启动成功
注意:jsw文件夹下有很多针对不同操作系统到文件夹,选中适合自己操作系统的文件夹。
也可以把start,stop做成脚本 放在桌面上,避免不停的cd
附件为start和stop的脚本,请打开脚本修改自己本机上nexus的路径。
3.打开nexus
在浏览器中访问: http://localhost:8081/nexus
出现
点击右上角的login in
输入帐号:admin
输入密码:admin123
登录成功
配置nexus
由于在新搭建的nexus环境中只是一个空的仓库,所以第一步就是要和远程的Maven中心仓库进行同步。
如果在Reindex之后,并没有同步到远程的仓库,可以检查每个仓库的设置。下面是Maven Central的设置:
开打maven目录 -> conf -> settings.xml
找到localRepository
上面到注释信息写道:Default: ~/.m2/repository
我们可以添加
<localRepository>${M3_HOME}/repository</localRepository>
${M3_HOME}是maven到安装路径,新建个repository文件夹用来装入本地的jar包
顺手把以前默认的repository删除。
#cd ~ #rm -rf .m2
依次在settings.xml文件里输入
<!-- nexus帐号和密码 --> <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> ... <!-- 引用naxus仓库组 --> <profile> <id>dev</id> <repositories> <repository> <id>nexus</id> <url>http://127.0.0.1:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <url>http://127.0.0.1:8081/nexus/content/groups/public</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> .. <!-- nexus --> <activeProfiles> <activeProfile>dev</activeProfile> </activeProfiles>
注意:根据标签位置准确输入
上传jar到本地仓库
选中3rd party 点击Artifact Upload标签
点击 select artifact(s) 按钮 选择要上传到jar包 然后再add artiffact -> uplaod artiffact 即可。
编辑pom.xml的时候可能找不到在nexus的jar包
在nexus里查询本地上传的jar包
复制xml代码到pom.xml文件保存即可。
编辑好pom.xml后保存
完毕后在${M3_HOME}/repository 文件里可看到导入的jar包。