maven工程配置私库「建议收藏」

maven工程配置私库「建议收藏」为什么要配置私库?从中央仓库下载速度缓慢,而且有些jar包是公司私有的包不存在在中央仓库当中,所以我们需要配置私库。首先去修改setting文件,在maven文件夹下的conf文件夹当中<?xmlversion=”1.0″encoding=”UTF-8″?><settingsxmlns=”http://maven.apache.org/SETTINGS/1.0.0″…

大家好,又见面了,我是你们的朋友全栈君。

为什么要配置私库?
从中央仓库下载速度缓慢,而且有些jar包是公司私有的包不存在在中央仓库当中,所以我们需要配置私库。

首先去修改setting文件,在maven文件夹下的conf文件夹当中

<?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">
  <!--设置本地仓库-->
  <localRepository>F:/.m2/repository</localRepository>
  
  <pluginGroups>
  </pluginGroups>

  <proxies>
  </proxies>

  <!--设置私库认证信息-->
  <servers>
	  <server>
	    <!--这里的id要与稍后配置的pom中的id一致-->
	    <id>nexus-releases</id> 
	    <username>admin</username>(这里用的是默认的用户名和密码 一般普通的私库都会有)
	    <password>admin123</password>
	  </server>
	  <server>
	    <id>nexus-snapshots</id>
	    <username>admin</username>
	    <password>admin123</password>
	  </server>
  </servers>
  
  <!--设置私库mirror 表示maven所有的请求都由nexus来处理-->
  <mirrors>
	<mirror>
		<id>nexus</id>
		<mirrorOf>*</mirrorOf>
		<name>Nexus Mirror.</name>
		<url>http://localhost:8081/nexus/content/groups/public</url>(在实际应用中如果连接的是别人的私库,localhost要改成对方的ip地址才行,路径也是不一样的)
	</mirror>
  </mirrors>

  <!--设置maven私库信息-->
  <profiles>  
	<profile>
		<id>nexus</id>
		<repositories>
		  <repository>
			<id>nexus</id>
			<name>Nexus</name>
			<url>http://localhost:8081/nexus/content/groups/public/</url>
			(在实际应用中如果连接的是别人的私库,localhost要改成对方的ip地址才行,路径也是不一样的)
			<releases><enabled>true</enabled></releases>
			<snapshots><enabled>true</enabled></snapshots>
		  </repository>
		</repositories>
		<pluginRepositories>
		  <pluginRepository>
			<id>nexus</id>
			<name>Nexus</name>
			<url>http://localhost:8081/nexus/content/groups/public/</url>
			(在实际应用中如果连接的是别人的私库,localhost要改成对方的ip地址才行,路径也是不一样的)
			<releases><enabled>true</enabled></releases>
			<snapshots><enabled>true</enabled></snapshots>
		  </pluginRepository>
		</pluginRepositories>
    </profile>
    <!--覆盖maven中央仓库设置开启releases和snapshots版本的下载-->
	<profile>
		<id>central</id>
		<repositories>
			 <repository>
				<id>central</id>
				<url>http://central</url>
				<releases><enabled>true</enabled></releases>
			    <snapshots><enabled>true</enabled></snapshots>
			</repository>
		</repositories>
		<pluginRepositories>
			<pluginRepository>
				<id>central</id>
				<url>http://central</url>
				<releases><enabled>true</enabled></releases>
			    <snapshots><enabled>true</enabled></snapshots>
			</pluginRepository>
		</pluginRepositories>
    </profile>
  </profiles>

  <!--激活私库信息的配置-->
	<activeProfiles>
	    <activeProfile>nexus</activeProfile>
		<activeProfile>central</activeProfile>
	</activeProfiles>
</settings>

在项目的pom文件中做如下设置

<distributionManagement>
	<repository>
		<id>nexus-releases</id>(注意id要与之前配的setting当中配的id对应)
		<name>Nexus Releases Repository</name>(随意取名)
		<url>http://localhost:8081/nexus/content/repositories/releases/</url>(连接别人的私库需要改成对方的ip地址和路径)
	</repository>
	<snapshotRepository>
		<id>nexus-snapshots</id>
		<name>Nexus Snapshots Repository</name>
		<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
	</snapshotRepository>
</distributionManagement>

转自:https://www.xuebuyuan.com/1868949.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/161250.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • MySQL连接查询

    MySQL连接查询首先创建两个表fruits表,包含水果id、名字、价格orders表,包含id和订单号(num)1.内连接查询(INNORJOIN)使用普通sql语句selectfruits.id,name,price,numfromfruits,orderswherefruits.id=orders.id;使用内连接查询语句(结果与上图相同)s…

    2022年4月30日
    34
  • C++学习——int、long、long long, double, long double等的占用空间及取值范围「建议收藏」

    C++学习——int、long、long long, double, long double等的占用空间及取值范围「建议收藏」unsigned int 0~4294967295int 2147483648~2147483647unsigned long 0~4294967295long 2147483648~2147483647long long的最大值:9223372036854775807long long的最小值:-9223372036854775808unsigned long lon…

    2022年8月18日
    14
  • 主从复制、读写分离、集群、为什么要使用Redis数据库[通俗易懂]

    主从复制、读写分离、集群、为什么要使用Redis数据库[通俗易懂]一、什么是主从复制、读写分离、为什么要使用主从复制:是一种数据备份的方案。简单来说,是使用两个或两个以上相同的数据库,将一个数据库当做主数据库,而另一个数据库当做从数据库。在主数据库中进行相应操作时,从数据库记录下所有主数据库的操作,使其二者一模一样。读写分离:是一种让数据库更稳定的的使用数据库的方法。是在有从数据库的情况下使用,当主数据库进行对数据的增删改也就是写操作时,将查询的…

    2022年6月13日
    24
  • 字符串有哪些_vue子组件emit方法失效

    字符串有哪些_vue子组件emit方法失效ES2017引入了字符串补全长度的函数。如果某个字符串的长度不够指定的长度,会在头部或尾部补全。padStart()用于头部补全,padEnd()用于尾部补全。’a’.padStart(3,’0′)//’00a’ ‘x’.padEnd(5,’ab’)//’xabab’ ‘x’.padEnd(4,’ab’)//’xaba’上面代码中,padStart()和padSt…

    2025年10月16日
    1
  • 12.Java- Maven 教程

    12.Java- Maven 教程一、安装引用菜鸟教程:Maven菜鸟教程地址1.下载1.Maven链接Maven下载地址:,点击跳转2.选择版本3.解压到指定地址4.并配置环境变量,引用的菜鸟教程引用菜鸟教程,菜鸟教程路径地址,点击跳转右键“计算机”,选择“属性”,之后点击“高级系统设置”,点击”环境变量”,来设置环境变量,有以下系统变量需要配置:新建系统变量MAVEN_HOME,变量值:E:\Maven\apache-maven-3.3.9编辑系统变量Path,添加变量值:;%M

    2025年10月4日
    3
  • C# 中List与json字符串的相互转换「建议收藏」

    C# 中List与json字符串的相互转换「建议收藏」将list转换成json字符串List<HingeType>hinges=[{id:1,name:hingeOne},{id:2,name:hingeTwo},···];StringhingeString=Newtonsoft.Json.JsonConvert.SerializeObject(hinges);将json字符串转换成listList<HingeType>hingeList=Newtonsoft.Json.JsonConvert.Deseria

    2022年10月17日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号