大数据学习——装私服nexus

(一)安装

解压之后

进入bin文件夹下 复制路径 D:software exus-2.12.0-01-bundle exus-2.12.0-01in

进入命令行窗口输入以下命令,安装成功

如果报错

'findstr' 不是内部或外部命令,也不是可运行的程序或批处理文件

这是PATH环境变量的问题,将windows命令的目录添加到PATH中就好了。

即:在path中追加:%SystemRoot%/system32;%SystemRoot%;

C:windowssystem32>cd D:software
exus-2.12.0-01-bundle
exus-2.12.0-01in

C:windowssystem32>cd D:software
exus-2.12.0-01-bundle
exus-2.12.0-01in

C:windowssystem32>d:

D:software
exus-2.12.0-01-bundle
exus-2.12.0-01in>nexus install
wrapper  | nexus installed.

D:software
exus-2.12.0-01-bundle
exus-2.12.0-01in>

去服务管理启动(我的电脑——管理——服务和应用程序——服务——nexus——启动)。

浏览器输入http://localhost:8081/nexus/

默认账号密码admin admin123

(二)构建索引

刚刚安装好的nexus是无法直接搜索到jar包的,必须下载索引才可以正常使用。

我们到中央仓库地址 http://repo.maven.apache.org/maven2/.index/ 下载以下两个索引压缩文件

nexus-maven-repository-index.gz

nexus-maven-repository-index.properties 

这两个文件一般在此页面的最后的位置,另外还需要在网上下载一个名为indexer-cli-5.1.1.jar jar

将以下三个文件放入一个文件夹

 

cmd执行:

java -jar indexer-cli-5.1.1.jar -u nexus-maven-repository-index.gz -d indexer

执行后生成目录indexer,目录下的文件是索引文件,如下图

D: exus-2.12.0-01-bundlesonatype-work exusindexercentral-ctx 目录下的文件删除,将上边的索引文件拷贝到此目录下。

拷贝后重新启动nexus,然后进入nexus搜索jar包发现可以进行搜索了。

(三)仓库类型

1hosted:宿主仓库,自己项目的jar要放到hosted类型的仓库中。

2proxy:代理仓库,代理中央仓库

3virtual:虚拟仓库,存储了maven1的构件,一般不用。

4group:仓库组,将一些仓库组成一个组,自己项目连接仓库组去下载jar包。

平常开发中都去连接仓库组,仓库组中包括:hostedproxy等。

仓库所在的文件夹见下面的截图:

(四)镜像配置

nexus已经安装好了,我们要开始使用它了。现在我们需要在maven的配置文件settings.xml中配置镜像,让maven找私服,而不是直接到中央仓库下载。

打开maven的配置文件settings.xml,添加如下配置:

<mirrors>    

<mirror>

      <id>nexus</id>

      <mirrorOf>*</mirrorOf>

      <url>http://localhost:8081/nexus/content/groups/public/</url>

    </mirror>

</mirrors>

mirrors为镜像组,可以配置多个mirror(镜像),我们这里配置的是nexus中的中央代理仓库。

配置好后,我们需要创建一个项目来测试一下,看看是不是可以通过nexus来下载jar包。

测试步骤:

创建maven工程(jar),在pom.xml中添加依赖,观察nexus中是否下载了相应的jar包,目录为 nexus-2.12.0-01-bundlesonatype-work exusstoragecentral

  1. 确保我们之前的案例做完.不要在这个案例上做私服
  2. 创建一个新的仓库,新的项目来完成私服案例

(五)发布自己的工程jarnexus

1. 创建maven工程itcastutil jar

坐标信息:  Group Id : cn.itcast.util  

            Artifact Id: itcastutil

创建包cn.itcast.util

创建类DateUtil

package cn.itcast.util;

import java.util.Calendar;

import java.util.Date;

/**

 * 日期工具类

 * @author Administrator

 *

 */

public class DateUtil {

/**

 * 获取当前年份

 * @return

 */

public static int getYear(){

Calendar calendar=Calendar.getInstance();

calendar.setTime(new Date());

return  calendar.get(Calendar.YEAR);

}

}

pom.xml中引入如下配置信息

<distributionManagement>

   <repository>

   <id>releases</id>

    <url>

             http://localhost:8081/nexus/content/repositories/releases/

       </url>

   </repository> 

   <snapshotRepository>

   <id>snapshots</id>

        <url>

            http://localhost:8081/nexus/content/repositories/snapshots/

        </url>

   </snapshotRepository> 

  </distributionManagement>

2. Maven中配置

将以下配置信息放入mavensettings.xml

  <servers>

<server>

      <id>releases</id>

      <username>admin</username>

      <password>admin123</password>

    </server>

<server>

      <id>snapshots</id>

      <username>admin</username>

      <password>admin123</password>

    </server>

  </servers>

注意:settings.xml 配置 <id>pom.xml<id> 对应!

然后执行命令  deploy  ,有如下提示表示部署成功

我们在私服中进行查询,发现可以查到刚才我们上传的jar

(六)发布第三方的工程jarnexus

有很多jar包由于版权等问题,并不会出现在中央仓库中,比如oracle的驱动,那如何将这类jar包放在nexus中呢?我们看下列操作步骤:

1)选择左侧菜单的Repositories,  Repositories窗口中选择3rd party

2)在3rd party窗口中选择Artifact Upload

3)在Artifact Upload选项卡中填写坐标,并上传jar包。

上传jar包选择oracle的驱动。

填写坐标

有下列提示则为上传成功

上传成功后可以在3rd party库中找到此jar

 

原文地址:https://www.cnblogs.com/feifeicui/p/10145274.html