Note
  • Introduction
  • JS
    • JS / JQuery 代码、框架收藏
    • 用Mock.js + AngularJS来提高开发效率
    • 在JavaScript中监听 IME 键盘输入事件
    • 如何组织大型JavaScript应用中的代码?
    • 深入理解javascript原型和闭包
      • 1. 一切都是对象
      • 2. 函数和对象的关系
      • 3. prototype原型
      • 4. 隐式原型
      • 5. instanceof
      • 6. 继承
      • 7. 原型的灵活性
      • 8. 简述【执行上下文】上
      • 9. 简述【执行上下文】下
      • 10. this
      • 11. 执行上下文栈
      • 12. 简介【作用域】
      • 13. 【作用域】和【上下文环境】
      • 14. 从【自由变量】到【作用域链】
      • 15. 闭包
      • 16. 补充:上下文环境和作用域的关系
    • AngularJS
      • AngularJS开发一些经验总结
      • AngularJS Controller 间通信机制
      • AngularJS 中的一些坑
      • 如何解决AngularJs在IE下取数据总是缓存的问题
      • AngularJS之$timeout指令
      • angular 代码日记
      • AngularJS Directive 隔离 Scope 数据交互
      • 在Angular指令中使用NgModelController做数据绑定
      • AngularJS的ngTransclude
      • 使用Angularjs的ng-cloak指令避免页面乱码
      • Directive - Compile vs. Link
    • NodeJS
      • npm的配置管理及设置代理
    • Angular
      • Angular2 - Control Validation on blur
      • Angular2 - how to call component function from outside the app
  • Go
    • How to Test Local Changes with Go Mod
  • Java
    • Java中根据字体得到字符串高度和长度
    • JAVA 判断一个字符串是不是一个合法的日期格式
    • JVM上的随机数与熵池策略
    • tomcat7+jdk的keytool生成证书 配置https
    • Spring
      • SpringMVC中用@ParamVariable传递的参数包含斜杠(/)时,匹配不了报404错误的解决方案
      • SpringMVC 中HttpMessageConverter简介和Http请求415 Unsupported Media Type的问题
      • Spring Boot 打包,分离依赖jar,配置文件
      • SpringBoot启动后 Stopping service [Tomcat]
      • spring-boot打包时排除第三方依赖
    • 第一个Eclipse插件
    • Eclipse 使用技巧
    • HighChart利用servlet导出中文PNG图片乱码问题解决
    • JDK中文字体在Linux操作系统的设置方案
    • Shiro
      • Shiro-Authentication(身份验证)
      • Shiro-Authorization(授权)
    • 详谈再论JAVA获取本机IP地址
  • Python
    • pip国内镜像源的配置
  • Linux
    • Shell脚本 bad interpreter:No such file or directory & /bin/bash^M: bad interpreter错误解决方法
    • 10个重要的Linux ps命令实战
    • Linux 下执行定时任务 crontab 命令详解
    • CentOS 7.x设置自定义开机启动,添加自定义系统服务
    • CentOS 7 下使用 Firewall
    • 在Ubuntu 12.04安装和设置SSH服务
    • 配置CENTOS YUM更新源
    • Linux下终端利器tmux
    • scp命令
    • Linux系统管理常用命令
    • 让你提升命令行效率的 Bash 快捷键 [完整版]
    • SELinux
    • Linux下 RabbitMQ的安装与配置
    • SELinux下更改mysql端口
    • centos 7 升级后yum install出现Exiting on user cancel
    • Linux Shell 通配符、元字符、转义符使用实例介绍
  • Other
    • Docker
      • Docker Proxy
    • Swagger
      • Spring MVC 集成 Swagger
    • Maven
      • maven plugin的execution出错
      • nexus repair或update index 没反应 速度慢 手动配置nexus index
      • nexus 搭建 maven 私服
      • Maven类包冲突终极解决小技若干
      • org.codehaus.plexus.archiver.jar.Manifest.merge(org.codehaus.plexus.archiver.jar.Manifest)
      • Maven 生命周期
      • wagon-maven-plugin
      • Maven中-DskipTests和-Dmaven.test.skip=true的区别
    • MySQL
      • is not allowed to connect to this MySQL server 解决办法
      • MySQL备份--mysql dump
      • MySQL启动中 InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes 的问题
      • MySQL修改root密码的多种方法
      • MySQL长事务导致的Table Metadata Lock
      • com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
      • 解决mysql插入数据时出现Incorrect string value: '\xF0\x9F...' for column 'name' at row 1的异常
    • HTTP
      • HTTP 协议中的 Transfer-Encoding
      • 四种常见的 POST 提交数据方式
      • HTTP 请求头中的 X-Forwarded-For
      • 传统轮询、长轮询、服务器发送事件与WebSocket
    • Raspberry
      • 系统安装配置
    • VIM
      • vim常用配置
      • 在vim中使用查找命令查找指定字符串
      • Vim缩进有关的设置总结
    • Git
      • github 同步一个 fork
      • Git 如何 clone 非 master 分支的代码
      • git提示error setting certificate verify locations解决办法
      • git设置和取消代理
      • How to Delete Commit History in Github
      • Windows下使用Beyond Compare作为git的比对与合并工具
    • 解决 Virtualbox 共享文件夹 cannot create symlink error 问题
    • nginx 403 forbidden 二种原因
    • VirtualBox的四种网络连接方式
    • 在Windows的CMD中如何设置支持UTF8编码?
    • nginx使用ssl模块配置HTTPS支持
    • 怎么查看WINDOWS端口被哪个程序占用
    • VMWare 随系统启动指定虚拟机
    • 使用命令行启动VirtualBox虚拟机
    • 该死的^M
    • install home-assistant mosquitto-broker and node-red on android
    • SSH原理与运用:远程登录、远程操作与端口转发
    • SVN mime-type 笔记
    • VirtualBox虚拟机网络配置(NAT + Host-only - Bridged)
    • VirtualBox绿色版的桥接网卡驱动安装
    • OAuth的改变
    • MavenActionUtil.getMavenProject(e.getDataContext()) is Null when developing a intellij plugin
    • Cygwin的安装和配置apt-cyg源
    • Zookeeper运维常用四字命令
    • svn sqlite[S11]: database disk image is malformed
Powered by GitBook
On this page
  • 本机环境
  • 版本选择
  • 配置 nexus 环境
  • 安装 nexus 服务
  • 启动 nexus
  • 登录 nexus
  • 停止 nexus
  • 修改 nexus 账号密码
  • 修改 nexus 端口
  • 仓库类型
  • 仓库组
  • maven settings.xml 配置
  • 发布构件
  • 发布快照
  • 发布第三方构件

Was this helpful?

  1. Other
  2. Maven

nexus 搭建 maven 私服

Previousnexus repair或update index 没反应 速度慢 手动配置nexus indexNextMaven类包冲突终极解决小技若干

Last updated 5 years ago

Was this helpful?

本机环境

Win 8 JDK 7 Maven 3.2 Nexus 2.11

版本选择

nexus 2.6 及 2.6+ 版本要求 jdk 1.7 或 1.7+ 版本(jdk 1.6 请选择 nexus 2.5 及 以下版本)。根据你现有的环境来选择合适的版本。 这里选择 (如果无法打开下载, 可将新标签页地址栏中的地址复制到迅雷等下载工具中进行下载)。 下载得到 nexus-2.11.0-bundle.zip 压缩包。解压缩里面的 nexus-2.11.0-02 目录,如我的 E:\setup\dev\servers\nexus, 最终得到的目录结构为 E:\setup\dev\servers\nexus\nexus-2.11.0-02。

配置 nexus 环境

NEXUS_HOME = E:\setup\dev\servers\nexus\nexus-2.11.0-02 Path = .;%NEXUS_HOME%\bin

安装 nexus 服务

如果你所使用的是 Win8 操作系统,以下操作需要管理员权限。在命令行中执行 nexus install(Win8 系统组合键为 Ctrl + X, A):

C:\WINDOWS\system32>nexus install
wrapper | nexus installed.

启动 nexus

在命令行中执行 nexus start:

C:\WINDOWS\system32>nexus start
wrapper | Starting the nexus service...
wrapper | Waiting to start...
wrapper | Waiting to start...
wrapper | Waiting to start...
wrapper | nexus started.

登录 nexus

默认的管理员账号是:admin, 密码是:admin123

停止 nexus

在命令行中执行 nexus stop:

C:\Users\fanlychie>nexus stop
wrapper | Stopping the nexus service...
wrapper | Waiting to stop...
wrapper | nexus stopped.

修改 nexus 账号密码

<user>
  <id>admin</id>
  <firstName>Administrator</firstName>
  <lastName>User</lastName>
  <password>2899441143e28aee7287e8da3d7211258f5edbd3</password>
  <status>active</status>
  <email>fanlychie@yeah.net</email>
</user>

修改 nexus 端口

打开 %NEXUS_HOME%\nexus-2.11.0-02\conf\nexus.properties, 修改 application-port 的值。重启 nexus:nexus restart 。

application-port=8081
application-host=0.0.0.0
nexus-webapp=${bundleBasedir}/nexus
nexus-webapp-context-path=/nexus

仓库类型

打开 Views/Repositories --> Repositories 视图 nexus 仓库分为 4 种,group(仓库组)、hosted(宿主仓库)、proxy(代理仓库)、virtual(虚拟仓库)。 我们自己开发的构件通常是发布到 hosted 仓库,proxy 用来代理远程的公共仓库,一个 group 可以包含多个 hosted/proxy 仓库。

仓库组

打开 Views/Repositories --> Repositories --> Public Repositories --> Configuration 视图 Configuration 栏的左边是仓库组仓库列表,右边是当前可选的仓库,可以从右边挑选合适的仓库加入到左边的仓库组,点击 Save 保存即可。 一个仓库组通常包含了多个仓库,仓库组中的仓库列表的顺序决定了构件下载时遍历的仓库的先后次序,因此,建议将远程中央仓库(Central)放 到仓库组的最后一项。

maven settings.xml 配置

在 settings.xml 配置文件中添加如下配置:

<servers>
  <server>
    <id>releases</id>
    <username>admin</username>
    <password>admin123</password>
  </server>
  <server>
    <id>snapshots</id>
    <username>admin</username>
    <password>admin123</password>
  </server>
  <server>
    <id>thirdparty</id>
    <username>admin</username>
    <password>admin123</password>
  </server>
</servers>
<mirrors>
  <mirror>
    <id>nexus</id>
    <mirrorOf>*</mirrorOf>
    <name>nexus public repositories</name>
    <url>http://127.0.0.1:8088/nexus/content/groups/public</url>
  </mirror>
</mirrors>

发布构件

在 nexus 中找到如下的视图页面: 复制以上的配置,粘贴到你的 pom.xml 配置文件中:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.fanlychie</groupId>
  <artifactId>proj</artifactId>
  <version>1.0.0</version>
  <packaging>jar</packaging>
  <name>proj</name>
  <url>http://maven.apache.org</url>
  <distributionManagement>
    <repository>
      <id>releases</id>
      <url>http://localhost:8088/nexus/content/repositories/releases</url>
    </repository>
  </distributionManagement>
</project>

这里需要注意的是,repository 节点的 id 需与 settings.xml 中配置的 server 节点的 id 相同,如果不相同,修改任意一方都可以,只 要让它们保持一致即可,否则,发布构件的时候会报 401,ReasonPhrase:Unauthorized 的错误,原因是无法认证用户的身份。 右键项目,Run As --> Maven build...,在 Goals 栏输入 deploy 或在命令行(cmd)执行 mvn deploy,在控制台若能看到 BUILD SUCCESS,表明构件发布成功。你可以在 nexus 的 Releases 仓库中找到这个构件。 发布构件的时候,如果想把源码也一起发布出去(执行 mvn dependency:sources 可获得源码),配置如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.fanlychie</groupId>
  <artifactId>proj</artifactId>
  <version>1.0.1</version>
  <packaging>jar</packaging>
  <name>proj</name>
  <url>http://maven.apache.org</url>
  <distributionManagement>
    <repository>
      <id>releases</id>
      <url>http://localhost:8088/nexus/content/repositories/releases</url>
    </repository>
  </distributionManagement>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>2.4</version>
        <executions>
          <execution>
            <id>attach-sources</id>
            <phase>install</phase>
            <goals>
              <goal>jar-no-fork</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

同一个构件是不允许发布两次的,先修改一下构件的版本,然后 deploy

发布快照

快照用于区分稳定与不稳定的构件(发布的版本就是稳定的,快照版本是不稳定的)。构件的升级通常会带来许多的不稳定性,需要不断的修复, 快照可以避免由于升级带来的不稳定性迫使的不停的升级版本号,最终造成版本号的泛滥的问题。快照允许重新发布,而不需要变更构件的版本号。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.fanlychie</groupId>
  <artifactId>proj</artifactId>
  <version>2.0.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>proj</name>
  <url>http://maven.apache.org</url>
  <distributionManagement>
    <repository>
      <id>releases</id>
      <url>http://localhost:8088/nexus/content/repositories/releases</url>
    </repository>
    <snapshotRepository>
      <id>snapshots</id>
      <url>http://localhost:8088/nexus/content/repositories/snapshots</url>
    </snapshotRepository>
  </distributionManagement>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>2.4</version>
        <executions>
          <execution>
            <id>attach-sources</id>
            <phase>install</phase>
            <goals>
              <goal>jar-no-fork</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

版本号含有 SNAPSHOT 的构件将发布到 Snapshots 仓库,否则,将发布到 Releases 仓库。执行发布命令:mvn deploy

发布第三方构件

步骤见下图的标注: 命令行方式发布: mvn deploy:deploy-file -DgroupId=自定义groupId -DartifactId=自定义artifactId -Dversion=版本号 -Dpackaging=jar -Dfile=JAR文件的路径 -Durl=http://127.0.0.1:8088/nexus/content/repositories/thirdparty -DrepositoryId=thirdparty

页面访问的入口地址:

先停止 nexus,打开 %NEXUS_HOME%\sonatype-work\nexus\conf\security.xml,修改即可。 nexus 的密码采用 SHA1 加密算法 ( ),将加密后的 SHA1 串(小写)拷贝覆盖原来的。重启 nexus:nexus restart 。

<server> 节点配置服务的账户密码,用于发布构件时进行身份和权限的认证。<mirror> 节点用于镜像的配置,具体用法参考 maven

http://www.sonatype.org/nexus/archived
nexus-2.11.0
http://localhost:8081/nexus
在线加密工具
镜像配置