天天看点

nexus-2.14.2-01-bundle构建maven私服

nexus-2.14.2-01-bundle构建maven私服

一、下载nexus

地址:​​https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/oss/nexus-2.14.8-01-bundle.zip;​​

二、解压nexus-2.14.8-01-bundle.zip到指定的盘符:

nexus-2.14.2-01-bundle构建maven私服

三、在bin/jsw下有不同的版本,根据自己的系统选择正确的版本,这里选择window 64位操作系统的版本。

nexus-2.14.2-01-bundle构建maven私服

四、启动服务

介绍:

console-nexus.bat  是以命令窗口的形式启动,关闭后服务停止

install-nexus.bat   是设置开机启动,在服务中可以看成到该服务为开机自动启动(推荐使用这种方式启动)

stop-nexus.bat      是停止服务

uninstall-nexus.bat  是卸载nexus

nexus-2.14.2-01-bundle构建maven私服

启动服务:

nexus-2.14.2-01-bundle构建maven私服

看控制台:

nexus-2.14.2-01-bundle构建maven私服

五、服务配置

启动后输入:​​http://localhost:8081/nexus​​  

nexus-2.14.2-01-bundle构建maven私服

进入在右上角Login登录,初始用户名:admin 密码:admin123:

nexus-2.14.2-01-bundle构建maven私服

登陆后界面:

nexus-2.14.2-01-bundle构建maven私服

1、修改登录密码:如图选中admin选项,然后右键:

nexus-2.14.2-01-bundle构建maven私服

2、配置参数,将Download Remote Indexes 设置为true

nexus-2.14.2-01-bundle构建maven私服

3、添加第三方jar包

  3.1、选择和填写参数(groupId、artifactId、version)都要填写

nexus-2.14.2-01-bundle构建maven私服

 3.2、选择上传的jar包

nexus-2.14.2-01-bundle构建maven私服

六、项目调用方法

1、配置maven的settings.xml文件

  1.1、设置jar包保存的本地目录(我设置的是D盘)

<!--设置自己的maven本地仓库-->
  <localRepository>D:/Program Files/maven_repository/repository</localRepository>      
nexus-2.14.2-01-bundle构建maven私服

 1.2、根据私服设置私服地址

nexus-2.14.2-01-bundle构建maven私服
<mirrors>
   <mirror>
     <!--此处配置所有的构建均从私有仓库中下载 *代表所有,也可以写central -->
     <id>nexus</id>
     <name>nexus</name>
     <!-- * 表示让所有仓库使用该镜像-->
     <mirrorOf>*</mirrorOf>
     <url>http://localhost:8081/nexus/content/groups/public/</url>
   </mirror>
  </mirrors>      
nexus-2.14.2-01-bundle构建maven私服

1.3 在setting.xml配置文件中增加配置:(只需要修改下图标注的Releases/Snapshots中对应的地址):

<profiles>
    <profile>
        <id>nexus</id>
        <repositories>
            <repository>
                <id>nexus-rs</id> <!--正式仓库id-->
                <!--name随便-->
                <name>Nexus Release Snapshot Repository</name>
                <!--地址是nexus中repository(Releases/Snapshots)中对应的地址-->
                <url>http://localhost:8081/nexus/content/repositories/releases/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>

            <repository>
                <id>nexus-snapshots</id>
                <!--地址是nexus中repository(Releases/Snapshots)中对应的地址-->
                <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
                <releases><enabled>true</enabled></releases>
                <snapshots><enabled>true</enabled></snapshots>
            </repository>

        </repositories>

        <!--插件仓库地址,各节点的含义和上面是一样的-->
        <pluginRepositories>
            <pluginRepository>
                <id>nexus-rs</id>
                <name>Nexus Release Snapshot Repository</name>
                <url>http://localhost:8081/nexus/content/repositories/releases/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
            <pluginRepository>
                <id>nexus-snapshots</id>
                <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
                <releases><enabled>true</enabled></releases>
                <snapshots><enabled>true</enabled></snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>
  </profiles>

 <!--激活配置-->
  <activeProfiles>
      <activeProfile>nexus</activeProfile> <!--profile下的id-->
  </activeProfiles>      
nexus-2.14.2-01-bundle构建maven私服

1.4 在eclipse中更换setting.xml文件:

nexus-2.14.2-01-bundle构建maven私服

七、项目测试:

1.1 在eclipse的maven工程的pom.xml文件中配置:

<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.14</version>
</dependency>      

1.2 保存,如图可显示从私服下载jar包:

nexus-2.14.2-01-bundle构建maven私服

1.3 可从maven_repository\repository\log4j\log4j 中查看已经加载了log4j1.2.14版本:

nexus-2.14.2-01-bundle构建maven私服

1.4 可从私服中索引log4j:

nexus-2.14.2-01-bundle构建maven私服
nexus-2.14.2-01-bundle构建maven私服

至此,私服就创建成功了。

八、将本地工程部署构建到Nexus,作为jar/web作为插件:

1、在本地仓库的setting.xml中配置如下:

<servers>
      <server>
      <!--这个ID要与下面的repository中的ID一致-->
      <id>releases</id>
      <!--nexus中配置的用户名密码-->
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  </servers>      
nexus-2.14.2-01-bundle构建maven私服

2、在需要构建的项目中修改pom.xml文件:

<distributionManagement>
  <repository>
    <id>releases</id>
    <name>Internal Releases</name>
    <url>http://localhost:8081/nexus/content/repositories/releases/</url>
  </repository>
  <snapshotRepository>
    <id>snapshots</id>
    <name>Internal Snapshots</name>
    <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
  </snapshotRepository>
</distributionManagement>      
nexus-2.14.2-01-bundle构建maven私服

3、右键项目-Run As-Maven build...,执行maven的deploy命令:

nexus-2.14.2-01-bundle构建maven私服
nexus-2.14.2-01-bundle构建maven私服

4、打开私服:

4.1由于项目pom.xml中设置了<version>0.0.1-RELEASES</version>发布版本:

nexus-2.14.2-01-bundle构建maven私服

    因此可以在私服的Releases中查看到已经部署的项目:

nexus-2.14.2-01-bundle构建maven私服

4.2 如果项目pom.xml中设置了<version>0.0.1-SNAPSHOT</version>快照版本:

nexus-2.14.2-01-bundle构建maven私服

那么部署以后可以在私服的Snapshots中查看到已经部署的项目:

nexus-2.14.2-01-bundle构建maven私服
<?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">

  <!-- 插件组 -->
  <pluginGroups>

  </pluginGroups>

  <!-- 代理组 -->
  <proxies>

  </proxies>

  <servers>
      <server>
      <!--这个ID要与下面的repository中的ID一致-->
      <id>releases</id>
      <!--nexus中配置的用户名密码-->
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  </servers>

  <!--设置自己的maven本地仓库-->
  <localRepository>D:/Program Files/maven_repository/repository</localRepository>

  <mirrors>
   <mirror>
     <!--此处配置所有的构建均从私有仓库中下载 *代表所有,也可以写central -->
     <id>nexus</id>
     <name>nexus</name>
     <!-- * 表示让所有仓库使用该镜像-->
     <mirrorOf>*</mirrorOf>
     <url>http://localhost:8081/nexus/content/groups/public/</url>
   </mirror>
  </mirrors>

  <profiles>
    <profile>
        <id>nexus</id>
        <repositories>
            <repository>
                <id>nexus-rs</id> <!--正式仓库id-->
                <!--name随便-->
                <name>Nexus Release Snapshot Repository</name>
                <!--地址是nexus中repository(Releases/Snapshots)中对应的地址-->
                <url>http://localhost:8081/nexus/content/repositories/releases/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>

            <repository>
                <id>nexus-snapshots</id>
                <!--地址是nexus中repository(Releases/Snapshots)中对应的地址-->
                <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
                <releases><enabled>true</enabled></releases>
                <snapshots><enabled>true</enabled></snapshots>
            </repository>

        </repositories>

        <!--插件仓库地址,各节点的含义和上面是一样的-->
        <pluginRepositories>
            <pluginRepository>
                <id>nexus-rs</id>
                <name>Nexus Release Snapshot Repository</name>
                <url>http://localhost:8081/nexus/content/repositories/releases/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
            <pluginRepository>
                <id>nexus-snapshots</id>
                <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
                <releases><enabled>true</enabled></releases>
                <snapshots><enabled>true</enabled></snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>
  </profiles>

 <!--激活配置-->
  <activeProfiles>
      <activeProfile>nexus</activeProfile> <!--profile下的id-->
  </activeProfiles>