您的位置:首页 > 其它

nexus安装、配置

2015-04-23 11:15 162 查看
1、下载nexus-latest-bundle.zip文件后,并解压到 D:\nexus下。

2、配置nexus的环境变量:先配置NEXUS_HOME的环境变量,新建一个系统变量:NEXUS_HOME , 路径是:D:\nexus\nexus-2.8.0-05,再配置path环境变量,在path值的末尾添加"%NEXUS_HOME%\bin\jsw\windows-x86-64"

3、配置完成后cmd命令执行D:\nexus\nexus-2.8.0-05\bin\jsw\windows-x86-64安装install-nexus.bat服务(在windows上可以到服务里面看到nexus服务),服务安装成功后执行start-nexus.bat启动服务,Nexus启动成功了,然后打开浏览器,访问http://127.0.0.1:8081/nexus(由于安装了服务,所以每次开机都会自启动)



4、配置maven使用nexus:

1) nexus三种类型仓库:

hosted,本地仓库,通常我们会部署自己的构件到这一类型的仓库。
proxy,代理仓库,它们被用来代理远程的公共仓库,如maven中央仓库。
group,仓库组,用来合并多个hosted/proxy仓库,通常我们配置maven依赖仓库组。
2)默认情况下,Maven依赖于中央仓库(https://repo1.maven.org/maven2),这是为了能让Maven开箱即用,但仅仅这么做明显是错误的,这会造成大量的时间及带宽的浪费。
在项目的pom.xml中可以配置Repository把仓库位置指定成nexus,这样做不好,对于多个maven项目都需要重复该配置。例如:pom.xml

<repositories>
  	<repository>
  		<id>nexus</id>
  		<name>nexus repository</name>
  		<url>http://localhost:8081/nexus/content/repositories/central/</url>
  	</repository>
  </repositories>


将Repository的配置放到$user_home/.m2/settings.xml中:

<settings>  
...  
<profiles>  
  <profile>  
    <id>dev</id>  
    <repositories>  
      <repository>  
        <id>local-nexus</id>  
        <url>http://127.0.0.1:8080/nexus/content/groups/public/</url>  
        <releases>  
          <enabled>true</enabled>  
        </releases>  
        <snapshots>  
          <enabled>true</enabled>  
        </snapshots>  
      </repository>  
    </repositories>  
  </profile>  
</profiles>  
<activeProfiles>  
  <activeProfile>dev</activeProfile>  
</activeProfiles>  
...  
</settings>

在settings.xml中写了一个profile,并插入<repositories>元素,并使用<activeProfile>元素自动将这个profile激活。这里的local-nexus仓库指向了刚才我们配置的Nexus中“Public Repositories”仓库组,也就是说,所有该仓库组包含的仓库都能供我们使用。

此外,我们通过<releases>和<snapshots>元素激活了Maven对于仓库所有类型构件下载的支持。这样,Maven就会从你的Nexus服务器下载构件了;由nexus从maven
central服务器下载。

为nexus设置镜像:

1) 通过上面的配置,如果nexus服务器停掉,这是maven无法访问nexus,这时maven还会主动连接mavencentral去下载相关构建;

2) 通过添加镜像,可以做到maven只能从nexus服务器上下载,即使nexus无法访问也不能从mavencentral中下载(只能由nexus去maven central服务器下载)。设置了镜像以后,镜像中的所有工厂统一通过一个指定的url去访问,如果镜像无法访问就不会去maven central再访问了。

<mirrors>	
 <mirror>
      <id>nexus-mirror</id>
      <mirrorOf>*</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://localhost:8081/nexus/content/groups/public/</url>
    </mirror>
  </mirrors>

添加完镜像以后,就不需要激活dev的repository了,因为所有的工厂都从镜像访问了。

1) 对于中央工厂(central),默认不支持snapshots,要修改可以通过maven/lib/maven-model-builder-3.2.3.jar中的pom.xml 把snapshots设置成true,但这种方式不好。可以在maven的setting.xml中配合一个central来覆盖原有的属性,例如:

<settings>  
...  
<profiles>  
  <profile>  
    <id>centralProfile</id>  
    <repositories>  
      <repository>  
        <id>central</id>  
        <url>http://*</url>  
        <snapshots>  
          <enabled>true</enabled>  
        </snapshots>  
      </repository>  
    </repositories>  
  </profile>  
</profiles>  
<activeProfiles>  
  <activeProfile>centralProfile</activeProfile>  
</activeProfiles>  
...  
</settings>


这样访问中央工厂时,就不到maven/lib/maven-model-builder-3.2.3.jar中找对应的属性了,直接通过setting.xml获得属性。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: