Maven nexus安装、配置和使用

来源:互联网 发布:网络神曲排行榜前十名 编辑:程序博客网 时间:2024/04/29 19:45
简介

        Nexus 可以代理并缓存 Maven 构件,当 Maven 需要下载构件的时候,就不需要反复的请求中央仓库。

        有些公司都不提供外网给项目组人员,因此就不能使用 Maven 访问远程的仓库地址,所以很有必要在局域网里找一台有外网权限的机器,搭建 Nexus 私服,然后开发人员连到这台私服上,这样的话就可以通过这台搭建了 Nexus 私服的电脑访问 Maven 的远程仓库。

        这样就相当于在我们本地的局域网搭建了一个类似中央仓库的服务器,我们开始将中央仓库的一些资料下载到私服务器上,然后平时我们的 Maven 项目就是直接访问局域网内的私服即可,既节省了网络带宽也会加速项目搭建的进程,这样对我们开发来说,对公司来说都是非常好的选择。

        当然也不一定要将 Nexus 部署到内网,也可以根据需要部署到公网。

安装Nexus(Linux下)


        Nexus是典型的Java Web应用,它有两种安装包,一种是包含Jetty容器的Bundle包,另一种是不包含Web容器的war包。      

        1. 下载 

        官网下载很麻烦,这里有下好的Bundle包(链接:http://pan.baidu.com/s/1c0hfJY4 密码:vw83


        2. 安装

         # tar xzvf nexus-oss-webapp-1.8.0-bundle.tar.gz


        3. 启动

        进入cd  /usr/nexus/nexus-2.11.2-06/bin

        ./nexus start

      (输入./nexus 回车可以查看其他命令Usage: ./nexus { console | start | stop | restart | status | dump } ) 

       nexus默认监听的端口是8081。那么我们就可以在浏览器中访问:http://host:8081/nexus   


配置Nexus


        默认的用户名和密码:admin/admin123(一般登陆以后要修改密码),端口如果有冲突可以在/usr/nexus/nexus-2.11.2-06/conf的nexus.properties里面修改,下面是一些必要的配置(把索引打开)

         

 
本地使用Nexus


        Maven安装可以参考 有道:Maven 介绍、安装使用.note,博客:Maven 介绍、安装使用


        settings.xml 配置私服地址

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
30
31
32
33
34
35
36
37
38
39
40
41
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
   
  <localRepository>${MAVEN_HOME}/repository</localRepository>
 
  <profiles>
  
    <profile>
       <id>dev</id>
          <repositories>
             <repository>
                 <id>nexus</id>
                 <url>http://xx.xx.xx.xx:8181/nexus/content/groups/public/</url>
                 <releases>
                    <enabled>true</enabled>
                 </releases>
                 <snapshots>
                    <enabled>true</enabled>
                 </snapshots>
              </repository>
            </repositories>           
            <pluginRepositories>
                <pluginRepository>
                    <id>nexus</id>
                    <url>http://xx.xx.xx.xx:8181/nexus/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
  </profiles>
  
  <activeProfiles>
        <activeProfile>dev</activeProfile>
    </activeProfiles
</settings>


上传中央仓库没有的Jar包到 Nexus

        

        使用 (拷贝到项目pom.xml使用)
        

        效果
        


参考
        《Maven实战》-许晓斌(PDF链接:http://pan.baidu.com/s/1pJvCyuB 密码:6asf),主要参考第九章


0 0
原创粉丝点击