CentOS7搭建Maven私服+安装Nexus+制作Jar包上传私服+Pom使用自己的Jar包

环境

CentOS7

步骤

  1. CentOS先安装jdk8 略
  2. 安装nexus

1. 安装Nexus

下载地址,去下载unix.tar.gz后缀的
https://help.sonatype.com/repomanager3/product-information/download

解压

cd /usr/local/src/
tar -zxvf nexus..  -C /usr/local/
mv nexus.. nexus3

解压后有两个目录
默认的仓库存放目录 /sonatype-work/nexus3/blobs/default/content

修改配置

cd /usr/local/nexus3

1:可修改端口默认8081
vim /usr/local/nexus3/etc/nexus-default.properties

2:修改要使用的jdk
vim /usr/local/nexus3/bin/nexus    第14行
	【
		INSTALL4J_JAVA_HOME_OVERRIDE=/usr/local/jdk8
	】

3:修改数据以及日志的存储位置
vim nexus.vmoptions
	【
	-XX:LogFile=./sonatype-work/nexus3/log/jvm.log 
	-Dkaraf.data=./sonatype-work/nexus3 
	-Djava.io.tmpdir=./sonatype-work/nexus3/tmp
	】
	
4:修改运行用户为root 
vim /usr/local/nexus3/bin/nexus.rc
	【
	run_as_user="root"
	】
	
5:设置开机自启动 
ln -s /usr/local/nexus3/bin/nexus /etc/init.d/nexus3
chkconfig --add nexus3
chkconfig nexus3 on

6:后台启动,启动比较慢等两分钟
/usr/local/nexus3/bin/nexus run &

7:访问,有防火墙的关掉
http://ip:8081

8:进页面登录
默认账号:admin
默认密码去查看:cat /usr/local/sonatype-work/nexus3/admin.password
...
登录后会提示设置新密码,和禁用匿名访问

在这里插入图片描述

创建私有仓库:
在这里插入图片描述
点击Create repository,maven2proxy)
在这里插入图片描述
Name就随便写,下面写阿里云的maven地址,拉到最下点Save
http://maven.aliyun.com/nexus/content/groups/public/
在这里插入图片描述
然后再创建一个自定义的仓库
在这里插入图片描述
Name随便写,Blob store是仓库jar包存放位置,
不改就默认在 …/sonatype-work/nexus3/blobs/default/content
然后点创建
在这里插入图片描述
点击这个maven-public
在这里插入图片描述
把刚才创建的两个库放入这个库组里,我这已经放进去了
咱们自定义的仓库放第一位,后面是maven仓库,接着阿里的
在这里插入图片描述
基本配置完了,把地址拷贝下来,maven中要用
在这里插入图片描述

2. 配置Maven

配置maven的setting.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

    <!--配置本机Maven自定义仓库-->
    <localRepository>D:\Maven\repository2</localRepository>

    <pluginGroups>
    </pluginGroups>
    <proxies>
    </proxies>

    <!--配置账号密码-->
    <servers>
        <server>
            <id>nexus</id>
            <username>admin</username>
            <password>你的nexus登录密码</password>
        </server>
    </servers>

     <!--配置私有仓库镜像-->
    <mirrors>
        <mirror>
            <id>nexus</id>
            <name>maven-public</name>
            <!--*指的是访问任何仓库都使用我们的私服-->
            <mirrorOf>central</mirrorOf>
            <url>http://192.168.75.3:8081/repository/maven-public/</url>
        </mirror>
    </mirrors>


    <profiles>
    	<!--配置jdk-->
        <profile>
            <id>jdk1.8</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>1.8</jdk>
            </activation>
            <properties>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
            </properties>
        </profile>

  	    <!--配置私有仓库下载源-->
        <profile>
            <id>nexus</id>
            <repositories>
                <repository>
                    <id>nexus</id>
                    <name>nexus-central</name>
                    <url>http://192.168.75.3:8081/repository/maven-public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>nexus</id>
                    <name>nexus-central</name>
                    <url>http://192.168.75.3:8081/repository/maven-public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>

    <activeProfiles>
        <activeProfile>nexus</activeProfile> <!--需要激活ID才生效-->
        <activeProfile>jdk1.8</activeProfile>
    </activeProfiles>
    
</settings>

Maven的配置也完事了,注意新建一个D:\Maven\repository2 目录存放jar
我这种方式是maven配置了,pom就不用配置了

3. 打包一个jar包上传

打开你的盗版IDEA,新建个纯java项目,建个包和类,写一个方法
在这里插入图片描述
编辑项目点加号
在这里插入图片描述
点第二个框,目录是src就行,点ok,再ok
在这里插入图片描述
打包项目,这时打包的项目是class文件,如果你操作错误打成java文件的jar包,你就用不了了
在这里插入图片描述
在这里插入图片描述
把这个jar包上传到Nexus
上传到自建的仓库
在这里插入图片描述
如果你的包依赖别的包,要勾选那个框
在这里插入图片描述
点Upload就上传好了,找到他把它复制下来,放在项目的pom文件中就好了
在这里插入图片描述
新建一个Springboot项目测试
在这里插入图片描述
这时就可以用了
在这里插入图片描述
我多上传了一个b包而已
想了解细节去百度吧
结束!
请添加图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值