maven私服搭理技术文

maven---9使用Nexus创建私服

2016-11-27  本文已影响4292人  zlcook

1Nexus简介

专业版

2安装Nexus

Nexus是典型的Java Web应用,他有两种安装包,一种是包含Jetty容器的Bundle包,另一种是不包含Web容器的war包。

2.1下载

下载,下载oss版
版本:nexus-3.1.0-04-win64.zip
jdk要求:1.8及以上。

nexus3.1参考文档

解压后有两个目录(安装目录、数据目录)


nexus-3.1.0-04-win64下文件
LICENSE.txt
NOTICE.txt
bin
deploy
etc
lib
public
system
The installation directory includes a number of nested directories:

LICENSE.txt and NOTICE.txt

contain legal details about the license and copyright notices.
bin

contains the nexus
 startup script itself as well as startup-related configuration files.

etc

contains configuration files.
lib

contains binary libraries related to Apache Karaf.
public

contains public resources of the application.
system

contains all components and plugins that constitute the application.

2.2常见命令

如使用命令行请使用管理员权限打开

2.2.1配置成服务

nexus.exe /install <optional-service-name>

默认服务名称为nexus。
安装成功


Paste_Image.png

在系统的服务中可以看到:

nexus安装成系统服务

配置成随系统启动

配置随系统启动

操作服务的其命令

nexus.exe /start <optional-service-name>   开启服务,(也可以在winds的服务界面操作)
nexus.exe /stop <optional-service-name>
nexus.exe /uninstall <optional-service-name> 卸载服务。

2.2.2启动nexus

启动成功,默认端口8081.登录界面,http://localhost:8081/

启动成功登录后界面

方案一
如果你将nexus配置成服务后,1.进入界面系统服务界面,直接启动服务后就可以,或者在命令行采用nexus.exe /start nexus,启动服务。

方案二(推荐方案一)
如果你没有将nexus配置成服务,则需要手动到命令行执行启动命令:
进入到bin/目录下

nexus.exe /run

出现下面文字就启动成功

Started Sonatype Nexus OSS 3.1.0-04

其它命令

nexus.exe start
nexus.exe stop
nexus.exe restart

2.2.3停止nexus

同样如果是配置成系统中的服务,则关闭服务就行,否则直接在命令行执行Ctr+C

2.2.4登录

进入nexus后,输入账号密码登录,admin/admin123

nexus的界面

2.2.5提示

为了在命令行中方便使用nexus.exe命令可以将其配置在系统环境变量中。

3Nexus的仓库与仓库组

Nexus包含了各种类型的仓库概念,包括代理仓库(proxy)、宿主仓库(hosted)、仓库组(group)、虚拟仓库(virtual)。每一种仓库都提供了丰富实用的配置参数,用户根据需求定制。

3.1Nexus内置的仓库

3.2案例理解概念

公司内部建立Nexus私服为公司项目提供服务,公司Maven项目X。

3.3Nexus仓库分类的概念

Maven可以直接从宿主仓库下载构件,也可以从代理下载,为了方便还可以从仓库组下载构件,仓库组没有时间内容,它会转向其包含的宿主仓库或者代理仓库获取实际的构件。

各种类型的Nexus仓库

3.4创建Nexus仓库

创建按钮 选择仓库格式和类型

3.4.1宿主仓库配置信息

宿主仓库配置信息

3.4.2代理仓库配置信息

代理仓库配置信息

案例

缓存失败信息后,再次连接又出错 设置缓存错误结果时间为0

3.4.3仓库组配置信息

仓库组配置信息

4配置Maven从Nexus下载构件

4.1确定nexus上仓库的地址。

获取要配置nexus仓库的地址
http://localhost:8081/repository/maven-public/

4.2在单个maven项目中配置

4.3配置全局范围(推荐)

4.3.1在setting中配置访问私服(方法一)

<settings>
 ...
    <!--配置Nexus仓库-->
    <profile>
       <id>nexus</id>
       <repositories>
        <repository>
          <id>nexus</id>
          <name>Nexus Repository</name>
          <url>http://localhost:8081/repository/maven-public/</url>
          <layout>default</layout>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
         <releases>
            <enabled>true</enabled>
          </releases>
        </repository>
      </repositories>

      <pluginRepositories>
        <pluginRepository>
            <id>nexus</id>
            <name>Nexus Repository</name>
            <url>http://localhost:8081/repository/maven-public/</url>
            <layout>default</layout>
            <snapshots>
              <enabled>true</enabled>
            </snapshots>
            <releases>
              <enabled>true</enabled>
            </releases>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <!--激活Nexus仓库配置  -->
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
...
</settings>

4.3.2通过镜像配置私服(方法二)(推荐)

<settings>
 ...

    <!--配置镜像-->
 <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <name>nexus mirror for all repositry</name>
      <url>http://localhost:8081/repository/maven-public/</url>
    </mirror>
    <!--配置Nexus仓库-->
    <profile>
       <id>nexus</id>
       <repositories>
        <repository>
          <id>central</id>
          <name>Central Repository</name>
          <url>https://repo.maven.apache.org/maven2</url>
          <layout>default</layout>
          <snapshots><enabled>true</enabled>  </snapshots>
         <releases><enabled>true</enabled>  </releases>
        </repository>
      </repositories>

      <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <name>Central pluginRepository</name>
            <url>https://repo.maven.apache.org/maven2</url>
            <layout>default</layout>
            <snapshots><enabled>true</enabled></snapshots>
            <releases><enabled>true</enabled></releases>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <!--激活Nexus仓库配置  -->
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
...
</settings>

解释

5部署构件至Nexus

5.1需求说明

5.2部署Maven项目构件至Nexus

开发生成的快照版本部署到Nexus中策略为Snapshot的宿主仓库中,项目正式发布的构件则应该部署到Nexus中策略为Release的宿主仓库中。

5.2.1获取Nexus中确定要部署的宿主仓库的连接

要部署到的远程仓库
http://localhost:8081/repository/maven-releases/
http://localhost:8081/repository/maven-snapshots/

5.2.2配置项目pom

 <!--配置项目生成的构件部署到Nexus私服上 -->
  <distributionManagement>
    <repository>
        <id>nexus-releases</id>
        <name>Nexus ReleaseRepository</name>    
        <url>http://localhost:8081/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
        <id>nexus-snapshots</id>
        <name>Nexus SnapshotsRepository</name>      
        <url>http://localhost:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
  </distributionManagement>

5.2.3在settings.xml配置仓库认证信息

因为不是所有人都可以部署构件到nexus仓库中的,关于认证信息就是拥有管理该仓库的用户,在下面有讲。

<settings>
 ....
  <servers>
 <!--配置nexus仓库认证信息-->
    <server>  
        <id>nexus-releases</id>  
        <username>admin</username>  
        <password>****</password>  
    </server>  
    <server>  
        <id>nexus-snapshots</id>  
        <username>admin</username>  
        <password>****</password>  
    </server>  
  </servers>
...
</settings>

5.2.4使用mvn命令

在项目根目录下执行部署命令,或者在开发工具中执行部署命令

mvn clean deploy

5.3手动部署第三方构件至Nexus仓库

5.3.1确定Nexus中要部署的3rd-party宿主仓库连接

该宿主仓库一般转为用来存放第三方构件的仓库。


Paste_Image.png

http://localhost:8081/repository/3rd-party/

5.3.2在settings.xml配置3rd-party仓库认证信息

该信息在下面使用

<server>  
        <id>nexus-3rd-party</id>  
        <username>admin</username>  
        <password>admin123</password>  
    </server>  

5.3.3命令行部署到nexus上

通过命令行来操作部署G:\5jar\edu.mit.jwi_2.3.3_jdk.jar目录下的jar包到nexus的3rd-party仓库中。
其中需要你自定义groupId,artifactId,version,packaging信息。其中的-Dfile填写jar的位置,-Durl填写nexus中3rd-party的连接,-DrepositoryId填写在settings.xml配置的认证信息的id。

mvn deploy:deploy-file  -Dfile=G:\5jar\edu.mit.jwi_2.3.3_jdk.jar -DgroupId=local.edu.stanford -DartifactId=edu.mit.jwi_jdk -Dversion=2.3.3 -Dpackaging=jar    -Durl=http://localhost:8081/repository/3rd-party/ -DrepositoryId=nexus-3rd-party

部署成功


手动部署到3rd-party仓库的构件

关于部署第三方构件到本地仓库,请查看maven---6仓库---->3.2.2.3安装第三方构件到本地仓库

6Nexus的权限管理

6.1需求

处于安全考虑,在组织内部中如果希望只有管理员才能配置Nexus,只有某些团队成员才能部署构件,或者更细要求,例如每个项目都有自己的Nexus宿主仓库,且只能部署项目构件至该仓库,Nexus提供了全面的权限控制特性,能让用户自由根据需求配置Nexus用户(user)、角色(role)、权限(privilege).

6.2介绍

nexus中关于安全的官方详细介绍

nexus操作界面

6.1.1权限privilege

权限

6.1.2角色(role)

nx-anonymous角色拥有的权限

6.1.3用户(user)

7Nexus的调度任务

创建任务

8其他私服软件

还没接触....

留言

有什么不懂的一起探讨一下吧,欢迎留下宝贵意见,喜欢就点个赞吧(哈哈),多谢鼓励。

上一篇 下一篇

猜你喜欢

热点阅读