Linux搭建自己的Maven私有仓库(nexus) |
您所在的位置:网站首页 › 自己搭建节点什么好处 › Linux搭建自己的Maven私有仓库(nexus) |
目录 1.安装maven仓库依赖 安装maven: 2.安装nexus 3.批量上传jar 1.安装maven仓库依赖nexus仓库依赖jdk,maven,我用的版本如下: jdk8 maven 3.6.3 nexus 3.37.1 jdk本机已安装,没有安装的可以自己参考linux安装jdk的方法 安装maven:可以yum安装也可以通过包安装,我这里通过包安装,使用的3.6.3版本 官网下载版本: Index of /dist/maven/maven-3 下载对应的bin文件压缩包上传到/usr/local文件夹下,解压文件 [root@bd local]# tar -zxvf apache-maven-3.6.3-bin.tar.gz配置环境变量 [root@bd local]# vi /etc/profile #添加如下内容 export MAVEN_HOME=/usr/local/apache-maven-3.6.3 export PATH=$MAVEN_HOME/bin:$PATH #保存 :wq刷新环境变量 [root@bd local]# source /etc/profile检查maven版本,如下正确显示版本号则代表maven安装完成 [root@bd local]# mvn -v Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /usr/local/apache-maven-3.6.3 Java version: 1.8.0_262, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64/jre Default locale: zh_CN, platform encoding: UTF-8 OS name: "linux", version: "3.10.0-1160.el7.x86_64", arch: "amd64", family: "unix" 2.安装nexusnexus官网下载地址:Download Archives - Repository Manager 3,下载OSS版本(免费) 上传到/usr/local文件夹下,解压 [root@bd local]# tar -zxvf nexus-3.37.1-01-unix.tar.gz修改配置文件 [root@bd conf]# vim /usr/local/nexus-3.37.1-01/etc/nexus-default.properties application-port= //你的端口号 application-host= //你的ip进入bin目录下,启动服务: [root@bd bin]# ./nexus start **************************************** WARNING - NOT RECOMMENDED TO RUN AS ROOT **************************************** If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script.报错,根据提示信息,修改系统配置 [root@bd bin]# vim /etc/profile #添加 export RUN_AS_USER=root [root@bd bin]# source /etc/profile再次启动 [root@bd bin]# ./nexus start **************************************** WARNING - NOT RECOMMENDED TO RUN AS ROOT **************************************** Starting Nexus OSS... Started Nexus OSS.根据配置的ip+port,浏览器打开,点击右上角sign in登陆 会提示admin初始密码位于/usr/local/sonatype-work/nexus3/admin.password下 cat /usr/local/sonatype-work/nexus3/admin.password找到密码登陆后需重置密码,设置为自己的密码 3.批量上传jar首先新建仓库,点击create repository,类型选择maven2 (hosted) 仓库名随便起
在新文件夹下创建一个 shell 脚本: [root@bd bd-repo]# touch mavenimport.sh #赋予权限 [root@bd bd-repo]# chmod +x mavenimport.sh [root@bd bd-repo]# vim mavenimport.sh添加如下内容: #!/bin/bash #copy and run this script to the root of the repository directory containing files # this script attempts to exclude uploading itself explicitly so the script name is important # Get command line params while getopts ":r:u:p:" opt; do case $opt in r) REPO_URL="$OPTARG" ;; u) USERNAME="$OPTARG" ;; p) PASSWORD="$OPTARG" ;; esac done find . -type f -not -path './mavenimport\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;执行shell脚本(根据自己仓库配置修改) ./mavenimport.sh -u admin -p admin -r http://xxxxx:8081/repository/bd_repo/耐心等待执行完毕,登陆对应仓库查看: |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |