linux下使用nexus搭建maven仓库

[root@localhost ~]# cd /home
[root@localhost home]# mkdir nexus
[root@localhost home]# cd nexus
下载
解压
[root@localhost nexus]# tar -xzvf nexus-2.11.2-03-bundle.tar.gz
[root@localhost nexus]# ls
nexus-2.11.2-03   sonatype-work
修改配置文件
[root@localhost nexus]# cd nexus-2.11.2-03/conf
[root@localhost conf]# vi nexus.properties
 
#Jetty section
application-port=8990      ##修改端口号
# nexus section
nexus-work=${bundleBasedir}/../sonatype-work/nexus 
 
配置用户
[root@localhost conf]# vi /home/nexus-2.11.2-03/bin/nexus
 
#RUN_AS_USER=
RUN_AS_USER=root
 
若有设置防火墙,需前往修改防火墙配置并重启防火墙
 
启动nexus
 
[root@localhost conf]# /home/nexus-2.11.2-03/bin/nexus start
 
停止nexus
 
[root@localhost conf]# /home/nexus-2.11.2-03/bin/nexus stop
 
 
-- 私有仓库配置 --
 
pom.xml配置
 
<!-- 私有仓库 -->
<repositories>
<repository>
<id>nexus</id>  <!--这个ID需要与新建的组group ID一致--> 
<name>Nexus Repository</name>
</repository>
</repositories>
 
注意:
在构建maven项目时,如果在私服中存在需要的构件,则会直接从私服中下载;如果私服中没有所需构件,则会先从网络上下载到私服,之后才会下载到本地
 
登录nexus
 
在浏览器打开:http://47.91.147.146:8990/nexus,登录:用户名admin  默认密码:admin123
 
设置deployment账户密码 
 
Security -- Users 点击 deployment 那一行,右键,Set Password
 
 
-- 自动打包配置 --
 
pom.xml配置
<!-- 自动打包 -->
<distributionManagement>
<repository>
<id>releases</id><!--这个ID需要与release仓库的Repository ID一致-->
</repository>
 
<snapshotRepository>
</snapshotRepository>
</distributionManagement>
 
setting.xml配置
 
<server>
        <id>releases</id>
        <username>deployment</username>
        <password>admin123</password><!--这个密码就是设置的密码-->
    </server>
    <server>
        <id>snapshots</id>
        <username>deployment</username>
        <password>admin123</password><!--这个密码就是设置的密码-->
    </server>
 
最后右键项目->Run As->Run Configurations双击左边选项卡的Maven Build新建一个
 
在Main选项卡的Goals 中输入 deploy , 勾选 Skip Tests
点击右下角 Run
最后就可以在仓库中看到打好的包
 
注意:
当pom.xml中同时配置了releases仓库和snapshots仓库时 pom.xml文件开头的版本配置<version>1.0.0-SNAPSHOT</version>为build到snapshots库,而<version>1.0.0</version>**不带-SNAPSHOT的会build到releases库,如果只配置了releases库而版本号写的是带-SNAPSHOT的,build到最后一步会报400错误
 






posted @ 2018-09-16 23:11  面向bug编程  阅读(163)  评论(0编辑  收藏  举报