maven搭建私自服

1、私服简介
私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件。有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库;否则,私服请求外部的远程仓库,将构件下载到私服,再提供给本地仓库下载。
在这里插入图片描述

2、安装jdk
2.1 jdk下载地址
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

2.2 安装目录

/usr/local/java

2.3 配置

vim /etc/profile

添加配置

export JAVA_HOME=/usr/local/java
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH

3、安装私服
3.1 下载
下载地址:http://www.sonatype.com/download-oss-sonatype

下载最新的nexus:

在这里插入图片描述

3.2 解压和创建链接

$ sudo tar xvf latest-unix.tar.gz -C /opt
$ sudo ln -s /opt/nexus-3.3.1-01/ /opt/nexus

3.3 创建 nexus 用户

$ sudo adduser nexus
$ sudo chown -R nexus:nexus /opt/nexus
3.4 授权
$ sudo chown -R nexus:nexus /opt/nexus
$ sudo chown -R nexus:nexus /opt/sonatype-work/
3.5 修改/opt/nexus/bin/nexus.rc
$ sudo vim /opt/nexus/bin/nexus.rc
run_as_user="nexus"   
:wq

3.6 安装服务

$ sudo ln -s /opt/nexus/bin/nexus /etc/init.d/nexus
$ sudo systemctl enable nexus
nexus.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig nexus on

3.7 启动服务
$ sudo systemctl start nexus
此时可以访问 http://localhost:8081,用户名:admin ,密码:admin123。

3.8 报错
在这里插入图片描述
如果报这个错误,可以通过2步骤配置jdk的方式解决。

3.9 添加代理仓库
由于访问中央仓库有时候会比较慢,这里我添加一个阿里云的代理仓库,然后优先级放到默认中央库之前,, 阿里云的maven仓库url为http://maven.aliyun.com/nexus/content/groups/public

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

然后再public组里面讲这个aliyun-proxy仓库加入,排在maven-central之前即可。

在这里插入图片描述
在这里插入图片描述

4、本地私服使用
4.1 maven 修改
可在maven的默认配置settings.xml中修改如下:

releases admin admin123 snapshots admin admin123 nexus * http://ip:8081/repository/maven-public/
<profiles>
    <profile>  
      <id>dev</id>
      <repositories>
        <repository>
          <id>Nexus</id>
          <url>http://ip:8081/repository/maven-public/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </snapshots>
        </repository>
      </repositories>
      <activation>
        <activeByDefault>true</activeByDefault>      
        <jdk>1.8</jdk>
      </activation>
      <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
      </properties>
    </profile>
</profiles>
<activeProfiles>
    <activeProfile>dev</activeProfile>
</activeProfiles>

4.2 项目修改

<distributionManagement>
    <repository>
        <id>releases</id>~~删除线格式~~ 
        <name>Releases</name>
        <url>http://ip:8081/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <name>Snapshot</name>
        <url>http://ip:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>
注意:上面的repository的id值一定要跟settings.xml文件中配置的server一致。

打包:mvn deploy

转载于:https://www.liangzl.com/get-article-detail-2547.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值