目前比较流行的使用nexus搭建maven私有服务器,其实很简单,它就是一个web系统,从官方下载的包默认内嵌了jetty容器,因此须要提早安装好JVM,并配置好环境变量,接下来只须要简单配置并运行便可。html
本文参考的博客:http://www.361way.com/nexus-maven-private-warehouse/3108.htmllinux
官方下载Nexus oos版本:https://www.sonatype.com/download-oss-sonatypeweb
安装下载后解压,有2个目录:nexus-3.4.0-02 sonatype-work浏览器
nexus-3.4.0-02 -> bin目录有3个文件nexus(执行程序)、nexus.rc(配置文件,配置运行nexus的用户)、nexus.vmproperties(配置文件,配置nexus运行JVM虚拟机参数)
只须要设置nexus.rc中为:run_as_user="lkqm", 注意nexus基于安全考虑lkqm不能是root。安全
启动中止
bin目录下执行: nexus start
启动,nexus status
查看运行状态, nexus run
运行并打印结果会占用终端,nexus stop
中止。服务器
注:Nexus3版本以上须要jdk1.8版本。linux安装nexus运行须要操做sonatype-work目录下文件,因此保证run_as_user指定的用户对整个目录有读写权限。maven
linux下安装命令参考:url
cd ~/donwload # 解压到指定目录 sudo mkdir /usr/local/nexus suod tar xzvf nexus-3.4.0-02-unix.tar.gz -C /usr/local/nexus # 修改nexus目录的权限 cd /usr/local/nexus sudo chown -R lkqm . # 修改配置文件nexus.rc # 运行 cd nexus-3.4.0-02/bin ./nexus start
浏览器中访问192.168.0.1:8081, 未登陆状态,只能查看服务器端哪些仓库,以及有那些包(jar), 左侧树形菜单brow点击能够查看。代理
点击右上角登陆后进入配置界面,默认的管理员帐户:admin, 密码admin123,左侧树形菜单:repository,进入仓库配置(CRUD)。unix
仓库分为3种:
到此服务端,配置完毕。
注:默认提供了多个仓库,能够参照配置。
为了让maven项目,从私有服务器下载组建(jar包),须要在maven的配置文件setting.xml -> mirrors添加mirror元素:
<mirror> <id>lkqm</id> <mirrorOf>central</mirrorOf> <name>My Server Maven.</name> <url>http://localhost:8081/repository/maven-public/</url> </mirror>
url标签的值,一般指向group类型的仓库,这样咱们就能够下载共有的和私有的组件(jar包)。
咱们须要将本身的组件(jar包)上传到私有的maven服务器中,须要在指定项目的pom.xml中,添加以下配置,而后执行maven命令deploy便可将项目打包上传到服务器:
<!-- 构建分发管理:本地构建上传到私有服务器 --> <distributionManagement> <repository> <id>nexus-releases</id> <name>Nexus Release Repository</name> <url>http://localhost:8081/repository/maven-release/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://localhost:8081/repository/maven-snapshot/</url> </snapshotRepository> </distributionManagement>
url标签的值,指向hosted类型的仓库,用于上传私有的组件(jar包)。
因为仓库须要帐户密码访问,所以根据上面配置的id的值,去maven配置文件setting.xml -> servers节点中查找,内容以下:
<servers> <server> <id>nexus-release</id> <username>admin</username> <password>199528</password> </server> <server> <id>nexus-snapshots</id> <username>admin</username> <password>199528</password> </server> </servers>