基于Docker搭建Maven私服环境(Nexus)

1.Nexus环境搭建
1.1 下载镜像
#1.下载一个nexus3的镜像
docker pull sonatype/nexus3
1.2 运行Nexus容器
#2.将容器内部/var/nexus-data挂载到主机/root/nexus-data目录
docker run -d -p 8081:8081 --name nexus -v /root/nexus-data:/var/nexus-data --restart=always sonatype/nexus3

关闭防火墙,访问http://ip:8081

进入容器获取初始密码:

docker exec -it nexus /bash/bin
vi /nexus-data/admin.password

默认登录账号:admin/获取的密码,并修改密码

1.3 创建私服账户和仓库

创建账户(wmh/wmh),并赋予权限

创建maven2(hosted),私人仓库:wmh-release

修改maven-central仓库中心仓库地址为阿里云仓库

http://maven.aliyun.com/nexus/content/groups/public/
1.4 修改本地maven,settings.xml文件
<mirrors>
    <mirror>
		<id>wmh</id>
		<name>Repository in My Orgnization</name>
		<url>http://192.168.75.128:8081/repository/maven-public/</url>
		<mirrorOf>*</mirrorOf>
	</mirror>
  </mirrors>
 

  <servers>
		<server>    
       <id>wmh</id>    
       <username>wmh</username>    
       <password>wmh</password>    
    </server>
  </servers>
  
   <profiles>

         <repository> 
		  <id>wmh</id> 
		  <url>http://192.168.75.128:8081/repository/maven-snapshots/</url> 
		  <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases> 
		  <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots> 
		</repository> 

  </profiles>
1.5 打包本地jar包到私服

添加pom依赖:

<!--注意限定版本一定为RELEASE,因为上传的对应仓库的存储类型为RELEASE -->
	<!--指定仓库地址 -->
	<distributionManagement>
		<repository>
			<!--此名称要和.m2/settings.xml中设置的ID一致 -->
			<id>wmh</id>
			<url>http://192.168.75.128:8081/repository/wmh-release/</url>
		</repository>
	</distributionManagement>

	<build>
		<plugins>
			<!--发布代码Jar插件 -->
			<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>
		</plugins>
	</build>

执行命令:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值