Linux 使⽤nexus 搭建maven 私服
⼀、准备⼯作
    系统:LINUX
JDK :已安装(未安装详见jdk 安装教程:wwwblogs/muzi1994/p/5818099.html )
Maven :已安装(未安装详见maven 安装教程:wwwblogs/muzi1994/p/6030181.html )
Nexus :
所有版本下载地址:
Nexus 是⼀个强⼤的Maven 仓库管理器,它极⼤地简化了⾃⼰内部仓库的维护和外部仓库的访问。
⼆、安装Nexus
  1.解压nexus ⽂件
1[root@centos6 var]# tar -zvxf nexus-2.12.
注:解压后有两个⽂件夹:
nexus-2.12.0-01: 是nexus 的核⼼⽂件
sonatype-work :maven 下载jar 存放地址
  2.启动Nexus
123456[root@centos6 nexus-2.12.0-01]# ./bin/nexus start  - ****************************************WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
If you insist running as root, then set the environment variable RUN_AS_USER=root before running this  script.
  默认情况下,不建议以root ⽤户运⾏Nexus ,可以修改bin/nexus 中的配置跳过警告(修改RUN_AS_USER=root )
1[root@centos6 nexus-2.12.0-01]# vi bin/nexus
重新启动Nexus
1
234567[root@centos6 nexus-2.12.0-01]# ./bin/nexus start
-
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************Starting Started Nexus OSS.
  注:Nexus 默认端⼝8081,如果想修改端⼝。修改/conf/nexus.properties ⽂件
访问⽹址:192.168.1.11:8081/nexus/#welcome
点击右上⾓的 Log In 按钮即可登陆了。默认登录账号/密码为: admin/admin123 ,登陆成功后的界⾯
  点击Repositories,将列表中所有Type为proxy 的项⽬的 Configuration 中的 Download Remote Indexes 设置为True
将Releases仓库的Deployment Policy设置为 Allow ReDeploy
当然我们也避免不了会使⽤到⼀些第三⽅的 jar ,⽽这些jar包也不存在于互联⽹上的maven中央仓库中,这时我们可以⼿⼯添加jar 到我们的私服中。
添加第三⽅ jar 如下:
填写完必选字段,点击Upload Artifact(s)按钮即可。
  3.配置本地项⽬引⽤私服
   ⾃动发布构件到远程仓库,在⼯程l中添加1
2 3 4 5 6 7 8 9 10<distributionManagement>
<repository>
<id>releases</id><!--这个ID需要与你的release仓库的Repository ID⼀致-->
<url>192.168.1.11:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id><!--这个ID需要与你的snapshots仓库的Repository ID⼀致-->        <url>192.168.1.11:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
  修改本地$MAVEN_HOME\conf⽬录下的l配置⽂件,添加如下配置1
2 3 4 5 6 7 8 9 10 11 12<servers>
<server>
<id>releases</id>
<username>admin</username>        <password>admin123</password>    </server>
<server>
<id>snapshots</id>
<username>admin</username>        <password>admin123</password>    </server>
</servers>
  在本地⼯程⽬录下执⾏:
1mvn deploy
  所部署的包就⾃动上传到了nexus安装⽬录下的
  4.配置Maven从Nexus下载构件
    在POM中配置Nexus私服,这样的配置只对当前的Maven项⽬有效。1
2
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29<!--指定Nexus的构件仓库-->
<repositories>
<repository>
<id>public</id>
<name>Team Maven Repository</name>
<url>192.168.1.11:8081/nexus/content/groups/public/</url>        <releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
linux安装jdk16</repository>
</repositories>
<!--指定Nexus的插件仓库-->
<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>Team Maven Repository</name>
<url>192.168.1.11:8081/nexus/content/groups/public/</url>        <releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
  在l中配置profile元素,这样就能让本机所有的Maven项⽬都使⽤⾃⼰的Maven私服。1
2 3 4 5 6 7 8 9 10 11 12 13<properties>
<repository>
<id>public</id>
<name>Team Maven Repository</name>
<url>192.168.1.11:8081/nexus/content/groups/public/</url>            <releases>
<enabled>true</enabled>
</releases>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository><br></properties>