爷的眼睛闪亮
insideDotNet En_summerGarden

下载nexus包,放入Linux中

vim etc/profile  在该文件最下方 加入:

export RUN_AS_USER=root

进入该nexus的包bin目录 ./nexus start 启动服务

在地址栏里输入服务IP地址和8081端口就可以打开用户界面,例如http://192.168.40.242:8081/nexus

点Sign In登录管理页面,用户名密码为,admin和admin123

在Repositories页面里显示着,默认已经创建了5个仓库(2个为group),直接可以拿来用,无需再自行创建仓库。

使用方法

搭建Maven私有仓库的主要目的,是为了在团队多人开发时,只要内网的私有仓库有下载过依赖的jar包,就直接从私有仓库获取,不再通过外网的中央仓库,毕竟外网的下载速度实在是太慢了。

在项目的pom.xml或者settings.xml文件里加入一下配置信息(区别,pom.xml是针对当前项目,settings.xml是全局的针对所有项目)

配置信息中的id,name和url跟上图中的仓库对应,type为proxy,说明它只是代理,只能用于下载jar包,不能用于发布项目。

<repositories>
    <repository>
        <id>maven-central</id>
        <name>maven-central</name>
        <url>http://192.168.204.132:8081/repository/maven-central/</url>
        <layout>default</layout>
        <snapshotPolicy>always</snapshotPolicy>
         <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

如果想把自己的项目发布到私有仓库中,可以用另外两个仓库,release和snapshots,至于这两个有啥区别,说白了就是,在版本号后面加“-SNAPSHOTS“”就自动发布到snapshots,不加的话就发布到releases

发布到仓库的命令是mvn clean deploy

    <distributionManagement>
        <repository>
            <id>maven-releases</id>
            <name>maven-releases</name>
            <url>http://192.168.204.132:8081/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>maven-snapshots</id>
            <name>maven-snapshots</name>
            <url>http://192.168.204.132:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

 其他使用细节

如果用的是eclipse,在settings.xml的配置如下

<profile>
      <id>localMaven</id>

      <activation>
        <jdk>localMaven</jdk>
      </activation>

      <repositories>
        <repository>
          <id>maven-central</id>
          <name>maven-central</name>
          <url>http://192.168.204.132:8081/repository/maven-central/</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
          <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
      </repositories>
    </profile>

这时候记得在eclipse里选择对应的profile

 

===========================================================================================

登录系统后点击左侧菜单栏Views/Repositories下的Repositories选择Central仓库点击下边的Configuration把Download Remote Indexes属性设为True保存即可。

然后在Central仓库上右键然后点击Repair Index 即可下载中心仓库的索引文件,稍等几分钟点击下边的Browse Index即可看见下载的索引文件。

往Public Repositories中添加Central仓库,点击Public Repositories在Configuration选项卡中把Central移到左侧即可

最后在自己的应用中把中心仓库配置成建立的私有仓库地址即可,修改本地的maven配置文件,C:\Documents and Settings\用户名\.m2\setting.xml

在mirrors添加mirror节点地址指向建立的私有仓库地址,mirrorOf属性值设为central为了覆盖超级pom中指定的central地址,如下

posted on 2017-05-08 10:22  爷的眼睛闪亮  阅读(8530)  评论(0)    收藏  举报