1.Nexus安装与配置

来源:互联网 发布:网络热点事件2017 编辑:程序博客网 时间:2024/04/30 11:34

1.Nexus下载
下载地址:http://www.sonatype.org/nexus/go/
下载后的文件:nexus-2.11.4-01-bundle.zip
安装:直接解压到某个目录即可
解压后,会有两个目录:
nexus-2.11.4-01  
sonatype-work :私服的默认仓库
1.1 将bin目录添加到环境变量中
D:\JavaDev\nexus-2.11.4\nexus-2.11.4-01\bin
1.2 配置java文件的路径
打开D:\JavaDev\nexus-2.11.4\nexus-2.11.4-01\bin\jsw\conf\wrapper.conf文件
修改wrapper.java.command=java为你的java.exe文件的路径
例如:
wrapper.java.command=D:\Program Files\Java\jdk1.7.0_07\bin\java
1.3 启动nexus
先安装:nexus install
然后启动:nexus start
C:\Users\Administrator>**nexus install**
wrapper  | nexus installed.
C:\Users\Administrator>**nexus start**
wrapper  | Starting the nexus service...
wrapper  | Waiting to start...
wrapper  | nexus started.
C:\Users\Administrator>
1.4 登陆nexus
地址:http://localhost:8081/nexus
默认用户名密码 admin/admin123

2.Nexus Repositories 介绍
2.1 Repositories介绍
在Nexus的Repositories中,主要有两种类型的工厂hosted和proxy
hosted本地工厂:只是面向内部服务的,面向局域网
3rd party :存放Maven中央仓库中没有的第三方jar包
Releases  :存放Maven中提交的Releases项目
Snapshots :存放Maven中提交的Snaphots项目
proxy代理工厂:
Central:存放从Maven中央工厂中下载下来的jar包
例如:Central中需要配置Maven中央工厂的地址
Apache Snapshots:存放专门从Apache下载的Snapshots的jar包
Codehaus Snapshots:存放专门从Codehaus下载的Snapshots的jar包
2.2 Maven中配置Nexus Repositories
配置Maven不从Maven自身的中央工厂找jar包,而是从这个Nexus私服工厂中找jar包
临时配置(用户配置):表示只针对当前项目的配置方式,只要当前项目找jar包的时候是来Nexus中找,但是如果再有一个新项目。就还是从Maven中来下载jar包了
打开pom.xml添加配置

1
2
3
4
5
6
7
<repositories>
     <repository>
         <id>nexus</id>
         <name>Nexus Repository</name>
         <url>http://localhost:8081/nexus/content/groups/public/</url>
     </repository>
</repositories>

其中url的值,就是Public repositories的URL值


全局配置:这样配置表示不管哪个项目,只要局域网内使用Maven下载jar包,都会来Nexus的私服工厂中来下载。
通过修改Maven的setting.xml的全局配置文件
增加一个或者多个profile配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<profiles>
    <profile>
        <id>nexusProfile</id>
        <repositories>
          <repository>
            <id>nexus</id>
            <name>Nexus Repository</name>
            <url>http://localhost:8081/nexus/content/groups/public/</url>
            <!-- releases默认是true -->
            <releases><enabled>true</enabled></releases>
            <!-- snapshots默认是false -->
            <snapshots><enabled>true</enabled></snapshots>
          </repository>
        </repositories>
      </profile>
</profiles>
<activeProfiles>
    <!-- 激活nexusRepo这个profile:只有激活才生效 -->
    <activeProfile>nexusProfile</activeProfile>
</activeProfiles>

2.3 配置Nexus的镜像
配置Nexus的镜像的目的是:有时候我们每个开发人员需要在我们的私服中找jar包,但是如果私服中也没有的话,就会去Maven的中央工厂中找。可能会有这样的需求,就是你们开发人员不允许直接去中央工厂找jar包,你们所需要的jar包都来我们内部的私服来找。如果私服里也找不到,那就是找不到了【通知项目经理需要\*\*.jar包】
同样是在Maven的全局配置文件settings.xml中配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<mirrors>
<mirror>
  <id>nexusMirror</id>
  <!-- 配置工厂镜像,只要mirror中配置的工厂需要找jar包,都来这个url中找[也就是都来私服中找]
  即使在这个私服中找不到了,也不会去Maven的中央工厂中找
  mirrorOf中配置的表示是工厂的id
  central工厂位置:apache-maven-3.3.9\lib\maven-model-builder-3.3.9.jar\pom-4.0.0.xml
  central工厂表示是Maven自己的工厂https://repo.maven.apache.org/
  maven2,这个地址就是Maven默认去找jar包的一个Maven中央工厂
   -->
   
  <!-- 这里也可以使用*号来代替所有的工厂都使用这个镜像来获取jar包
  <mirrorOf>nexus,central</mirrorOf>
  -->
  <mirrorOf>*</mirrorOf>
  <name>Human Readable Name for this Mirror.</name>
  <url>http://localhost:8081/nexus/content/groups/public/</url>
</mirror>
</mirrors>

当然,如果这里定义mirror,那上面定义的激活profile的定义就没什么意义了,可以直接注释掉

1
2
3
4
<activeProfiles>
    <!-- 激活nexusRepo这个profile:只有激活才生效 -->
    <!-- <activeProfile>nexusProfile</activeProfile> -->
</activeProfiles>
0 0
原创粉丝点击