Linux基于nexus3搭建maven私服

1.安装jdk1.8
JDK下载地址:http://www.oracle.com/technetwork/cn/java/javase/downloads/jdk7-downloads-1880260.html
一:将下载下来的文件进行解压 到/usr目录下 tar -xzf jdk-8u74-linux-x64.tar
二:配置环境变量 编辑/etc/profile文件在末尾加入jdk的执行路径,如:
export JAVA_HOME=/usr/jdk1.8.0_74
export JRE_HOME=$JAVA_HOME/jre
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
三: 使配置文件生效 source /etc/profile
或者直接使用yum的方式安装

2.安装maven 同样官网下载压缩版, 然后解压, 将执行路径/bin添加到环境变量即可.最后更改一下maven的源。编辑settings.xml作如下修改

<mirror>
  <id>alimaven</id>
  <name>aliyun maven</name>
  <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  <mirrorOf>central</mirrorOf> 
</mirror>

3.安装nexus3
下载地址:https://pan.baidu.com/s/13mtczlErtLTdpoBCxIc-tg 提取码:l61m
解压 tar -zxvf nexus-3.6.0-02-unix.tar.gz -C /usr/local/

4.进入bin目录,修改nexus3的运行用户为root
vim nexus.rc
run_as_user=“root”

5.给nexus文件赋予执行权限
cd /usr/local/nexus-3.6.0-02/bin/
chmod 777 nexus
启动nexus3 ./nexus run &

6.开启远程访问端口 nexus3默认端口是:8081
firewall-cmd --zone=public --add-port=8081/tcp --permanent
firewall-cmd --reload

7.设置开机自启动(systemctl方式)
systemctl enable nexus
重新加载配置文件
systemctl daemon-reload
最后使用默认账号:admin/admin123 登录验证

使用方式:
首先登录到nexus的maven-central界面把proxy改为国内的仓库
在这里插入图片描述
idea创建一个项目,找到idea用到的maven的配置文件
在这里插入图片描述
打开此文件,作如下编辑:
mirrors节点添加如下nexus的仓库(mirrors节点表示依次去如下仓库寻找jar包,注:nexus的maven-public仓库包括了下面要说的maven-snapshots, maven-central, maven-releases三个仓库)
在这里插入图片描述
在这里插入图片描述

     <!-- nexus仓库-->
    <mirror>
        <id>nexus</id>
        <mirrorOf>*</mirrorOf>
        <url>http://193.112.130.28:8081/repository/maven-public</url>
    </mirror>
       <!-- ali镜像-->
    <mirror>
        <id>alimaven</id>
        <mirrorOf>central</mirrorOf>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
    </mirror>
       <!-- 官方镜像-->
     <mirror>
            <id>repo1</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo1.maven.org/maven2/</url>
    </mirror>

servers节点添加:(id表示某个要发布的jar是什么版本类型)
在这里插入图片描述

 <server>  
         <id>nexus-releases</id>  
         <username>xx</username>  
         <password>xx</password>  
 </server>  
 <server>  
         <id>nexus-snapshots</id>  
         <username>xx</username>  
         <password>xx</password>  
 </server>  

添加完成后,打开idea工程某个module的pom文件,添加如下distributionManagement和build节点
在这里插入图片描述

 <distributionManagement>
        <repository>
            <id>nexus-releases</id>    //**这里的id必须要和上面server节点的id一致,不然提示401错误**
            <name>Nexus Release Repository</name>
            <url>http://193.112.130.28:8081/repository/maven-releases/</url>  //表示点击deploy时本地jar要发布到nexus的maven-releases仓库
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <name>Nexus Snapshot Repository</name>
            <url>http://193.112.130.28:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
    <build>
        <plugins>
            <!-- 要将源码也发布上去,需要加入这个插件 -->
            <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <attach>true</attach>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
   </build>

最后点击deploy将项目安装到nexus,后续要引用就可以直接从nuxus拉取了
在这里插入图片描述
如果拉取jar时,本地maven的settings.xml没有添加上面所说的nexus的镜像,那也可以在pom中添加如下节点

<repositories>
        <repository>
            <id>maven-public</id>
            <name>maven-public</name>
            <url>http://193.112.130.28:8081/repository/maven-public</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
 </repositories>

当然也可使用命令上传jar包到nexus

发布不带有pom的jar包
mvn deploy:deploy-file -DgroupId=<group-id> \
 -DartifactId=<artifact-id> \
 -Dversion=<version> \
 -Dpackaging=<type-of-packaging> \
 -Dfile=<path-to-file> \
 -DrepositoryId=<id-to-map-on-server-section-of-settings.xml> \
 -Durl=<url-of-the-repository-to-deploy>
注:-DrepositoryId的值即为在setttings.xml里面配置的server id。 

发布带有pom的jar包
mvn deploy:deploy-file -DpomFile=<path-to-pom> \
 -Dfile=<path-to-file> \
 -DrepositoryId=<id-to-map-on-server-section-of-settings.xml> \
 -Durl=<url-of-the-repository-to-deploy>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值