docker安装maven私服
Nexus简介
Nexus是一个强大的Maven仓库管理器,它极大地简化了自己内部仓库的维护和外部仓库的访问。利用Nexus
你可以只在一个地方就能够完全控制访问 和部署在你所维护仓库中的每个Artifact。Nexus是一套“开箱即用”的
系统不需 要数据库,它使用文件系统加Lucene来组织数据。Nexus 使用ExtJS来开发界面,利用Restlet来提供
完整的REST APIs,通过m2eclipse与Eclipse集成使用。Nexus支持WebDAV与LDAP安全身份认证。
下载镜像
docker pull sonatype/nexus3
创建文件存储目录
mkdir -p /docker/nexus/data
运行镜像
docker run -d \
-p 8081:8081 \
--name nexus \
-v /docker/nexus/data:/var/nexus-data \
--privileged=true \
--restart=always \
sonatype/nexus3
参数 | 说明 |
---|---|
-d | 以守护进程的方式启动 |
-p 8081:8081 | 把容器内的端口8081挂载到宿主机8081上面 |
- -name nexus | 容器的名字 |
-v /docker/nexus/data:/var/nexus-data | 把容器内的目录挂载到 /docker/nexus/data目录 |
- -privileged | 使得容器内的root拥有真正的root权限。 |
- -restart | 自动重启 |
sonatype/nexus3 | 镜像的名字 |
登录
http://localhost:8081/
帐号是: root
root密码默认在docker镜像里的admin.password文件里
docker exec -ti nexus /bin/bash
cat /nexus-data/admin.password
创建用户
配置maven的setting.xml文件
默认的maven配置文件在用户目录下的.m2隐藏目录下
<servers>
<server>
<!--身份证唯一标识-->
<id>test</id>
<!--maven私服的帐号-->
<username>test</username>
<!--maven私服的密码-->
<password>19951224</password>
</server>
</servers>
<!-- mirrors是全局配置,对所有的项目都用私服-->
<mirrors>
<mirror>
<!--对应server里面的id-->
<id>test</id>
<mirrorOf>central</mirrorOf>
<name>Nexus Mirror</name>
<!--配置maven私服的仓库地址-->
<url>http://192.168.0.119:8081/repository/maven-public</url>
</mirror>
</mirrors>
手动上传第三方jar到私服
查看jar包的依赖信息
maven项目中引入刚刚上传的jar
<dependency>
<groupId>com.ljm</groupId>
<artifactId>test</artifactId>
<version>v1.0</version>
</dependency>
通关mvn命令发布jar包到maven私服中
pom.xml配置以下信息
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ljm</groupId>
<artifactId>test2</artifactId>
<!--
version
后缀名有强一致性要求,不然打包发布不到私服上面去
RELEASE 生产版本 对应下面 distributionManagement里配置的私服里的 maven-releases仓库
SNAPSHOT 快照版本 maven-snapshots仓库
-->
<version>1.0-RELEASE</version>
<!--发布jar包到maven私服 -->
<distributionManagement>
<repository>
<!--此名称要和.m2/settings.xml中设置的ID一致 -->
<id>test</id>
<url>http://192.168.0.119:8081/repository/maven-releases/</url>
</repository>
</distributionManagement>
<!--maven私服的仓库地址,项目中如果设置了,则不需要配置 m2目录下的setting.xml中的mirror-->
<repositories>
<repository>
<!--此名称要和.m2/settings.xml中设置的ID一致 -->
<id>test</id>
<name>nexus public</name>
<url>http://192.168.0.119:8081/repository/maven-public/</url>
</repository>
</repositories>
<build>
<finalName>test2</finalName>
<!--发布代码到nexus私服需要配置以下插件 -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
执行打包命令
mvn deploy
查看刚刚用命令发布的jar
总结
使用docker安装maven私服还是比较简单的,
如果不用maven私服的话,对于maven的中央仓库上没有的第3方的jar包,
只能copy到项目下的lib目录里了,这样上传到git服务器上代码量就很大了。
努力朝着顶级架构师的方向前进 。。。