03.maven连接nexus私服配置以及maven settings.xml文件详解
2018-03-01 22:54
477 查看
settings.xml有什么用?
如果在Eclipse中使用过Maven插件,想必会有这个经验:配置settings.xml文件的路径。
settings.xml文件是干什么的,为什么要配置它呢?
从settings.xml的文件名就可以看出,它是用来设置maven参数的配置文件。并且,settings.xml是maven的全局配置文件。而pom.xml文件是所在项目的局部配置。
Settings.xml中包含类似本地仓储位置、修改远程仓储服务器、认证信息等配置。
settings.xml文件位置
settings.xml文件一般存在于两个位置:
全局配置: ${M2_HOME}/conf/settings.xml
用户配置: {user.home} 和和所有其他系统属性只能在3.0+版本上使用。请注意windows和Linux使用变量的区别。
配置优先级
需要注意的是:局部配置优先于全局配置。
配置优先级从高到低:pom.xml> user settings > global settings
如果这些文件同时存在,在应用配置时,会合并它们的内容,如果有重复的配置,优先级高的配置会覆盖优先级低的。
maven怎么从远程仓库下载jar包,setting中配置:
Nexus配置
项目使用nexus私服的jar包,在项目的pom.xml文件中指定私服仓库
项目使用nexus私服的插件,在项目的pom.xml文件中指定插件仓库
如果想本机所有的maven项目都使用私服的组件,可以在maven的设置文件settings.xml中添加属性,并激活
如何将自己的项目发布到nexus私服
我们知道用mvn install命令可以将项目装载的本地的仓库,但是项目发布到私服,maven项目就要使用命令:mvn clean deploy;
要想发布项目到nexus里,必须通过标签来进行配置。在之前的文章中有介绍nexus的工厂类别,其中提到两个:hosted里的Releases、Snapshots.
当我们发布项目到nexus里时,如果项目版本是x.x.x-Releases,则会发布到Releases工厂中;而项目版本是x.x.x-SNAPSHOTS则发布到Snapshots工厂中。
需要在pom文件中配置一下代码;
注意还需要配置mvn发布的权限,否则会报401错误,在settings.xml中配置权限,其中id要与pom文件中的id一致
这里面的username和password对应的是nexus私服中具有发布权限的用户名和密码
参考文件:
http://blog.csdn.net/u012225679/article/details/73740785
https://www.cnblogs.com/jingmoxukong/p/6050172.html?utm_source=gold_browser_extension
http://blog.csdn.net/moshenglv/article/details/52027125
http://blog.csdn.net/haohaizijhz/article/details/72841489
https://www.cnblogs.com/h–d/p/5719040.html
http://blog.csdn.net/cwh056056/article/details/49667971
如果在Eclipse中使用过Maven插件,想必会有这个经验:配置settings.xml文件的路径。
settings.xml文件是干什么的,为什么要配置它呢?
从settings.xml的文件名就可以看出,它是用来设置maven参数的配置文件。并且,settings.xml是maven的全局配置文件。而pom.xml文件是所在项目的局部配置。
Settings.xml中包含类似本地仓储位置、修改远程仓储服务器、认证信息等配置。
settings.xml文件位置
settings.xml文件一般存在于两个位置:
全局配置: ${M2_HOME}/conf/settings.xml
用户配置: {user.home} 和和所有其他系统属性只能在3.0+版本上使用。请注意windows和Linux使用变量的区别。
配置优先级
需要注意的是:局部配置优先于全局配置。
配置优先级从高到低:pom.xml> user settings > global settings
如果这些文件同时存在,在应用配置时,会合并它们的内容,如果有重复的配置,优先级高的配置会覆盖优先级低的。
maven怎么从远程仓库下载jar包,setting中配置:
<!-- 我们使用maven下载需要的jar包,但是很多的时候由于中央仓库没有,所以此处可以在maven的设置中心添加多个下载仓库,当中央仓库没有的话,继续到下一个仓库去下载。这样丰富了中央仓库的下载地址。 --> <mirror> <id>nexus</id> <name>nexus maven</name> <url>http://localhost:8081/repository/maven-public/</url> <mirrorOf>*</mirrorOf> </mirror> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>repo2</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://repo2.maven.org/maven2/</url> </mirror> </mirrors>
Nexus配置
项目使用nexus私服的jar包,在项目的pom.xml文件中指定私服仓库
<repositories> <repository> <id>nexus</id> <name>nexus</name> <url>http://192.168.1.103:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>
项目使用nexus私服的插件,在项目的pom.xml文件中指定插件仓库
<pluginRepositories> <pluginRepository> <id>nexus</id> <name>nexus</name> <url>http://192.168.1.103:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories>
如果想本机所有的maven项目都使用私服的组件,可以在maven的设置文件settings.xml中添加属性,并激活
<profile> <id>Nexus</id> <repositories> <repository> <id>nexus</id> <url>http://localhost:8081/repository/maven-public/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <url>http://localhost:8081/repository/maven-public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <!-- 激活 --> <activeProfiles> <activeProfile>Nexus</activeProfile> </activeProfiles>
如何将自己的项目发布到nexus私服
我们知道用mvn install命令可以将项目装载的本地的仓库,但是项目发布到私服,maven项目就要使用命令:mvn clean deploy;
要想发布项目到nexus里,必须通过标签来进行配置。在之前的文章中有介绍nexus的工厂类别,其中提到两个:hosted里的Releases、Snapshots.
当我们发布项目到nexus里时,如果项目版本是x.x.x-Releases,则会发布到Releases工厂中;而项目版本是x.x.x-SNAPSHOTS则发布到Snapshots工厂中。
需要在pom文件中配置一下代码;
<distributionManagement> <repository> <id>nexus-releases</id> <name>Nexus Release Repository</name> <url>http://localhost:8081/repository/maven-releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://localhost:8081/repository/maven-snapshots//</url> </snapshotRepository> </distributionManagement>
注意还需要配置mvn发布的权限,否则会报401错误,在settings.xml中配置权限,其中id要与pom文件中的id一致
<!--授权信息 --> <server> <id>nexus-releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>nexus-snapshots</id> <username>admin</username> <password>admin123</password> </server>
这里面的username和password对应的是nexus私服中具有发布权限的用户名和密码
参考文件:
http://blog.csdn.net/u012225679/article/details/73740785
https://www.cnblogs.com/jingmoxukong/p/6050172.html?utm_source=gold_browser_extension
http://blog.csdn.net/moshenglv/article/details/52027125
http://blog.csdn.net/haohaizijhz/article/details/72841489
https://www.cnblogs.com/h–d/p/5719040.html
http://blog.csdn.net/cwh056056/article/details/49667971
相关文章推荐
- maven搭建nexus私服settings.xml配置
- maven settings.xml配置文件详解
- Maven配置文件settings.xml详解
- maven搭建项目,settings.xml配置文件,以及parent的pom.xml
- maven安装和eclipse集成以及Maven之setting.xml配置文件详解
- maven settings.xml配置文件详解
- MyEclipse 配置maven项目pom.xml设置 上传项目到nexus私服,通过中转仓库下载插件,以及nexus的配置
- maven的settings.xml配置文件详解
- maven全局配置文件settings.xml详解
- maven全局配置文件settings.xml详解
- maven配置settings.xml文件详解
- Struts配置文件详解,web.xml以及struts-cofig.xml,以及struts-cofig.xml中各个标
- Maven系列1--settings.xml 配置详解
- 02_Maven配置文件Pom.xml详解
- Maven基础-默认中央仓库[settings.xml 配置详解 ]
- Maven系列1--settings.xml 配置详解
- maven的setting.xml文件配置详解
- 学习笔记——Maven settings.xml 配置详解
- maven项目配置时私服nexus以及仓库repository的一些情况
- Maven配置文件Pom.xml详解