maven

Nexus 搭建本地仓库(私服)

2018-01-08  本文已影响169人  Real_man

为什么要搭建nexus本地仓库?

借助Sonatype Nexus我们可以搭建本仓库。

过程

  1. 具体系统下载对应自己系统的软件包,我下载Linux的软件包
    Nexus下载地址
wget -c https://sonatype-download.global.ssl.fastly.net/nexus/3/nexus-3.7.1-02-unix.tar.gz -O /usr/local/src
  1. 解压与运行
tar -xf nexus-3.7.1-02-unix.tar.gz
ln -sv /usr/local/src/nexus-3.7.1-02 /usr/local/nexus
### 启动nexus服务器
/usr/local/nexus/bin/nexus start
  1. 查看nexus运行状况
    浏览器打开nexus运行电脑的地址,默认端口是8081,查看运行状况


    nexus webui

点击copy会出现本地仓库服务器的地址,在开发项目的时候配置当前指向的源地址就可以了。

  1. 具体的设置可以点击最上方的设置按钮,根据需要配置自己需要的源。

不同语言源配置

  1. maven如果针对具体某个项目,直接在pom.xml中配置
    <repositories>
        <repository>
            <id>local</id>
            <name>250hosted</name>
            <url>http://192.168.8.250:8081/repository/maven-central/</url>
        </repository>
    </repositories>
### 下面这一块是用来上传我们自己的jar包到本地仓库的,如果不需要可以不要写。
    <distributionManagement>
        <repository>
            <id>nexus</id>
            <name>internel</name>
            <layout>default</layout>
            <url>http://192.168.8.250:8081/repository/maven-snapshots/</url>
        </repository>
    </distributionManagement>

额外: 也可以直接配置maven的setting.xml文件,全局都指向本地仓库。

// setting.xml文件中
// 指向本地源
 <localRepository>/path/to/local/repo</localRepository>
//指定maven连接网络时可以使用的一系列代理服务器
<proxies></proxies> 

//指定连接到特定服务器的认证信息
 <servers>
    <server>
      <id>nexus</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
</servers>

//当mavne环境profile生效的时候下面的profile也生效
<profiles>
    <profile>
      <id>dev</id>
      <repositories>
        <repository>
          <id>nexus</id>
          <name>local maven center</name>
          <url>http://192.168.8.250:8081/repository/maven-central/</url>
          <layout>default</layout>
           <snapshotPolicy>always</snapshotPolicy>
        </repository>
   </repositories>
  </profile>
</profiles>

  1. npm的配置
    可以通过npm config set registry=本地服务器地址,也可也通过npmrc文件来配置,npmrc文件一般位于如下位置

编辑npmrc文件内容为如下。

registry=http://192.168.8.250:8081/repository/250npm/

2.1 查看具体的配置信息

npm config ls -l
npmrc的配置位置

附录

上一篇 下一篇

猜你喜欢

热点阅读