ava Maven项目之Nexus私服搭建和版本管理应用

目录:

  • Nexus介绍
  • 环境、软件准备
  • Nexus服务搭建
  • Java Maven项目版本管理应用
  • FAQ

1、Nexus介绍

Nexus是一个强大的Maven仓库管理器,它极大地简化了自己内部仓库的维护和外部仓库的访问。利用Nexus你可以只在一个地方就能够完全控制访问 和部署在你所维护仓库中的每个Artifact。我们可以在局域网搭建一个maven私服,用来部署第三方公共构件或者作为远程仓库在该局域网的一个代理。

2、环境、软件准备

本次演示环境,我是在本机mac上操作,以下是我本地软件及版本:

  1. Nexus:nexus-2.14.4-03
  2. Jdk:1.8.0_91
  3. Maven:3.3.9
  4. Git: 2.10.1
  5. GitLab:8.17.4

注意:Java Maven项目版本管理,这里我们scm使用git来做版本管理,gitlab作为代码存储,这里我们忽略Jdk、Maven、Git、GitLab的安装过程,着重介绍下Nexus的搭建,以及Java Maven项目配置以及版本管理配置。

3、Nexus服务搭建

这里我们使用Nexus OSS开源版本,官网下载地址:Nexus Repository Manager OSS,这里我选择2.x的tag.gz包下载安装,安装到我本地/Users/wanyang3目录下。

1)解压缩下载包

cd /Users/wanyang3
tar -zxvf nexus-2.14.4-03-bundle.tar.gz 解压缩后,会在当前目录nexus-2.14.4-03-bundle下出现两个目录: nexus-2.14.4-03:nexus服务目录,包括日志,配置、启动、应用。 sonatype-work:nexux存储目录,下载上传的各个包存贮在这里。

2) 修改配置并启动服务

修改配置:
cd /Users/wanyang3/nexus-2.14.4-03-bundle/nexus-2.14.4-03/conf vim nexus.properties 说明:该文件是nexus的配置属性文件,application-port默认服务端口8081,因为本地8081端口已经占用,所以我们这里修改为9998,即:application-port=9998,其他配置,如nexus-work、runtime、application-host、nexus-webapp等默认即可。 启动: cd /Users/wanyang3/nexus-2.14.4-03-bundle/nexus-2.14.4-03/bin ./Nexus start Usage: ./nexus { console | start | stop | restart | status | dump } 注意:若启动报错,说没有权限启动,或者让指定USER时,有两种方法解决: 1. 使用RUN_AS_USER=root ./Nexus start命令启动 2. 修改Nexus文件,设置打开注释,并设置RUN_AS_USER=root,以后只需要执行./Nexus start即可。 

 

3)设置Nexus 
成功启动Nexus后,我们可以浏览器访问http://127.0.0.1:9998/nexus/,就可以看到Nexus服务Web管理页面欢迎页面了。

nexus

3.1 创建仓库 
点击右上角Log In,输入用户名和密码登录,Nexus默认账户用户名为admin,密码为admin123,登录以后,我们现在可以创建一个个人仓库了。点击左侧Repositories,我们可以看到默认的所有的仓库列表。

这里写图片描述

我们可以看到仓库类型有四种:

  1. hosted(宿主仓库):用来部署自己,第三方或者公共仓库的构件
  2. proxy(代理仓库):代理远程仓库
  3. virtual(虚拟仓库):默认提供了一个Central M1虚拟仓库,用来将maven 2适配为maven 1
  4. group(仓库组):统一管理多个仓库

这里我们选择类型为hosted的创建一个wanyang3的Repositories,注意选择Deployment Policy时,如果该仓库多次部署的话,请选择Allow Redeploy,否则后续部署会报错。

这里写图片描述

3.2 设置用户及权限 
点击左侧Security—》Users,设置用户及权限。 
我们可以看到有三个默认的账号:

  1. Admin(管理员账号):Nexus管理员权限,最高权限,什么操作都可以做。
  2. Deployment(部署账号):Nexus部署权限,以及所有仓库的CRUDV操作权限。
  3. Anonymous(匿名账号):Nexus匿名权限,以及所有仓库只读权限。

我们正常访问仓库的时候,是不需要这三个账户的,一般我们会把Deployment账户暴漏出来,方便开发或运维部署项目使用,我们可以直接使用该部署账号,亦可以新创建一个自己的账号信息,通过Add Role Management来控制该账号的权限。

这里写图片描述

注意:这里要记住设置的用户名和密码,下边配置Maven Setting.xml的时候配置用户名和密码信息。

Java Maven项目版本管理应用

一、Java Maven项目基本配置

我们先来看一个最基础的pom.xml文件,我们要达到的目的是,让我们依赖的jar包,从我们刚配置的Nexus私服上拉取和存储。

<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>com.wanynag3.efp</groupId> <artifactId>efp_demo</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>war</packaging> <name>efp_demo</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <spring.version>4.3.2.RELEASE</spring.version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-oxm</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4.7</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.10</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.10</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>1.7</source> <target>1.7</target> 

转载于:https://www.cnblogs.com/a-du/p/9040495.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值