搭建nexus上传jar包,并结合jenkins运行项目

一、搭建nexus

1、docker拉取镜像

需要将docker原更新一下

https://blog.csdn.net/qx020814/article/details/140908006?spm=1001.2014.3001.5502

bash 复制代码
docker pull sonatype/nexus3

创建nexus挂载文件、增加权限:

bash 复制代码
mkdir docker_nexus3
mkdir docker_nexus3/nexus-data
chown -R 200 docker_nexus3/nexus-data
chmod 777 docker_nexus3/nexus-data/

2、运行镜像

bash 复制代码
docker run -d --name=nuxus -v /docker_nexus3/nexus-data:/nexus-data -p 6000:6000 -p 8088:8081 sonatype/nexus3:latest

查看默认的admin密码:

cat docker_nexus3/nexus-data/admin.password

访问页面服务器ip:8088

没有登录时,只能查看数据

右上角登录后,就可以配置自己的仓库了

这里nexus默认创建了一个maven的仓库,分为四个:

使用Nexus3搭建Maven私服+上传第三方jar包到本地maven仓库 - Endv - 博客园 (cnblogs.com)

Hosted有三种方式,Releases、SNAPSHOT、Mixed

Releases: 一般是已经发布的Jar包

Snapshot: 未发布的版本

Mixed:混合的

3、添加jar包

我是直接在hosted 标识的仓库下添加jar包,添加后,会同步到group中:

我上班的时候,用第三方的私有jar包,老是看不见源码,也就没有注释,所以我这里专门去查了

如何吧源码加到仓库中:

(1)、增加一个打包源码的插件:

XML 复制代码
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

(2)、打包源码:

XML 复制代码
 mvn source:jar

然后就能在项目目标文件下查找到了:

写好唯一地址标识:

4、引用私有仓库jar包

修改Maven配置

XML 复制代码
  <servers>
<server>
    <id>my_maven</id>
    <username>admin</username>
    <password>123456</password>
</server>

  </servers>

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |  -->
  <mirrors>
  
    <mirror>
     <id>my_maven</id>
     <mirrorOf>central</mirrorOf>
     <name>本地私有仓库</name>
     <url>http://192.168.126.160:8088/repository/maven-public/</url>
    </mirror>
	
  </mirrors>

分别是添加用户密码、设置仓库地址 id自定义、mirrorOf固定central、name自定义、url在nexus中复制:

然后和以前一样,引用jar包就可以了,但是这里要想查看源码,必须吧源码也引用一次,不知道为啥:

二、修改jenkis的maven配置文件

我这里直接查找了jenkins的maven地址,然后吧配置文件替换了,最简单、有效果的方法就是这个:

XML 复制代码
find / -name "settings.xml"

咱们刚开始运行docker的时候,把jenkins的文件挂载到宿主机上的,所以直接需改宿主机上的文件就好。

我本来是在jenkins网页端配置了,一直使用原配置文件,索性就把原配置文件给它改掉,我看它还报不报错!!

相关推荐
(:满天星:)5 小时前
第31篇:块设备与字符设备管理深度解析(基于OpenEuler 24.03)
linux·运维·服务器·网络·centos
小陶来咯6 小时前
【仿muduo库实现并发服务器】Acceptor模块
运维·服务器
cui_hao_nan6 小时前
Docker后端部署
运维·docker·容器
ZZH1120KQ6 小时前
Linux系统安全及应用
linux·运维·系统安全
小扎仙森7 小时前
关于服务器宝塔转移wordperss子比主题问题
运维·服务器
小小小糖果人7 小时前
Linux云计算基础篇(5)
linux·运维·服务器
我不是哆啦A梦7 小时前
破解风电运维“百模大战”困局,机械版ChatGPT诞生?
运维·人工智能·python·算法·chatgpt
weixin_7714323117 小时前
linux系统 weblogic10.3.6(jar) 下载及安装
linux·运维·jar
scuter_yu8 小时前
主流零信任安全产品深度介绍
运维·网络·安全
开开心心就好8 小时前
免费PDF处理软件,支持多种操作
运维·服务器·前端·spring boot·智能手机·pdf·电脑