Maven Nexus 私有库搭建结合 idea开发配置

来源:互联网 发布:平面设计软件图标 编辑:程序博客网 时间:2024/06/04 19:06

1、搭建Nexus 私有服务器

    环境准备:

    操作系统:

      

  [root@localhost ~]# cat /etc/redhat-release        CentOS Linux release 7.2.1511 (Core)

    JDK 安装

       下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

      

      tar -xzf jdk1.8.0_121.tar.gz       mkdir /usr/java       mv jdk1.8.0_121 /usr/java       echo 'JAVA_HOME=/usr/java/jdk1.8.0_121' >>/etc/profile       echo 'export PATH=$PATH:$JAVA_HOME:$JAVA_HOME/bin' >>/etc/profile       source /etc/profile

    Nexus 安装

        下载地址: https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.14.5-02-bundle.zip

        wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.14.5-02-bundle.zip        unzip nexus-2.14.5-02-bundle.zip        mv nexus-2.14.5-02-bundle /usr/local/nexus

     Nexus 启动 

       /usr/local/nexus/bin/nexus start

       起来后访问地址: http://主机IP:8081   默认密码: admin admin123

        注意:如果端口8081 被占用,会启动不起来。如果端口起来了,访问不了,那么关闭防火墙,或开放端口

        关闭防火墙: systemctl stop firewalld  

         开发端口:    firewall-cmd --add-port=8081/tcp --permanent; firewall-cmd --reload



           Nexus 私有仓库有 

          group   组  组合其他的私有仓库, 如图 public  统一对外的仓库地址

          hosted  本地私有仓库   存储第三方jar 包(如果oracle 驱动jar)  

          proxy     转发私有仓库    向中央仓库下载jar 包

          virtual   虚拟仓库


创建用户


        选择Nexus user 进行创建用户


2、 Maven 配置setting.xml

       注:下载maven 自行下载http://maven.apache.org/  setting.xml 常存放本地位置为 maven 家目录的conf/setting.xml 或者 m2./setting.xml 这两个位置

  

<?xml version="1.0" encoding="UTF-8"?><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>D:\commons\apache-maven-repos</localRepository><servers><server><id>gpdi</id><username>gpdi</username><password>gpdi333</password></server></servers><mirrors><!-- <mirror><id>aliyun</id><mirrorOf>*</mirrorOf><name>aliyun</name><url>http://maven.aliyun.com/nexus/content/groups/public</url></mirror> --><mirror>    <id>gpdi</id><mirrorOf>gpdi333</mirrorOf><name>gpdi</name><url>http://192.168.147.128:8081/nexus/content/groups/public/</url></mirror></mirrors><profiles><profile><id>nexus</id>           <repositories><repository><id>io.spring.repo.maven.release</id><url>http://repo.spring.io/release/</url><snapshots><enabled>false</enabled></snapshots></repository><repository><id>io.spring.repo.maven.milestone</id><url>http://repo.spring.io/milestone/</url><snapshots><enabled>false</enabled></snapshots></repository><repository><id>gpdi</id><name>gpdi</name><url>http://192.168.147.128:8081/nexus/content/groups/public/</url><layout>default</layout><snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots></repository>              </repositories></profile></profiles><activeProfiles><activeProfile>nexus</activeProfile></activeProfiles></settings>
              

 3、 IDE 调用私有仓库Pom.xml 配置

              在 <project></project> 里面添加<distributionManagement>

              

<project>   ...   <distributionManagement>    <repository>        <id>gpdi</id>        <name>release</name>        <url>http://192.168.147.128:8081/nexus/content/repositories/releases/</url>    </repository>    <snapshotRepository>        <id>gpdi</id>        <name>snapshots</name>        <url>http://192.168.147.128:8081/nexus/content/repositories/snapshots/</url>    </snapshotRepository>  </distributionManagement>   ...</project>

    注意: repository 的ID 要与 setting.xml 配置的一致。

   配置好了上面的,如果IDE 出现maven deploy " return code 401" 错误那么检查IDE 使用的setting.xml 文件是否是配置的setting.xml

   例如: IDEA

        file --> setting   选择配置好setting.xml 然后点击OK 。重新deploy

    

   

    

         至此nexus, maven,ide 开发环境安装配置完成,如有什么问题欢迎留言。

原创粉丝点击