Maven 使用 Nexus搭建私服

  • 1、安装自己的 Nexus 服务器

安装方法这里就不做介绍了,网上下载一下直接安装就可以了,也可以下载 war 包的,放在 tomcat 类型的 web server 下面,直接运行。

Nexus 可以安装在 windows 上,也可以安装在 Linux 上面。

  • 2、配置 Maven 的 settings.xml 文件

首先,在 节点下,配置自己的 server

<servers>
	<server>
		<id>releases</id>
		<!-- 默认的用户名和密码 -->
		<username>admin</username>
		<password>admin123</password>
	</server>
	<server>
		<id>snapshots</id>
		<username>admin</username>
		<password>admin123</password>
	</server>
</servers>

其次,配置镜像,让所有的 jar 包都在自己私服的镜像上面去找,如果自己的镜像上面没有,私服会自己通过默认设置的代理在公共镜像上去查找

<mirrors>
	<!-- 阿里云仓库-国内建议使用 -->
	<mirror>
		<id>alimaven</id>
		<!-- <mirrorOf>central</mirrorOf> -->
        <mirrorOf>*</mirrorOf>
		<name>aliyun maven</name>
		<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
	</mirror>
	<!--<mirror>
		<id>nexus</id>
		<mirrorOf>*</mirrorOf>
		<name>Nexus mirror</name>
		<url>http://localhost:8081/nexus/content/groups/public</url>
	</mirror>-->
  </mirrors>

然后,配置其使用的环境 Profiles:

<profiles>
	<profile>
		<id>dev</id>
		<repositories>
			<repository>
				<id>nexus</id>
				<!-- 这里的 url 是 public 镜像的路径,提供的对外的接口,两个都是一样的 -->
				<url>http://localhost:8081/nexus/content/groups/public</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>true</enabled>
					<updatePolicy>always</updatePolicy>
				</snapshots>
			</repository>
		</repositories>            
		<pluginRepositories>
			<pluginRepository>
				<id>nexus</id>
				<url>http://localhost:8081/nexus/content/groups/public</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>true</enabled>
					<updatePolicy>always</updatePolicy>
				</snapshots>
			</pluginRepository>
		</pluginRepositories>
	</profile>
</profiles>

同时,设置默认的使用环境:

<activeProfiles>
    <activeProfile>dev</activeProfile>
</activeProfiles>
  • 3、如果需要将自己的 jar 包上传至私服,需要在自己的项目的 pom.xml 配置文件中做如下配置:
<project>
  <distributionManagement>
    <repository>
    	<!-- 这里的 id 需要使用 settings.xml 中 servers 节点配置的 -->
        <id>releases</id>
        <name>Releases</name>
        <!-- 这里的url是nexus中releases镜像的路径 -->
        <url>http://192.168.xx.xx:8081/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <name>Snapshots</name>
        <!-- 这里的url是nexus中snapshots镜像的路径 -->
        <url>http://192.168.xx.xx:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
  </distributionManagement>
</project>
  • 4、最后,通过 maven 的 deploy 命令,将自己的 jar 上传至私服。
    run as > maven build > 输入命令 clean deploy > 运行
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值