maven项目中pom文件配置nexus仓库
2017-07-06 15:12
537 查看
在上一章节中,重点介绍了如何搭建nexus,搭建成功之后关键在于如何运用到项目中,下面将结合实际项目做简单介绍。
windows下搭建nexus仓库:http://blog.csdn.net/hh12211221/article/details/74010609
1、在setting.xml文件中配置nexus仓库,如下所示:
注:
在配置远程仓库时,中央仓库的id为central,远程url地址为http://repo.maven.apache.org/maven2。
在setting.xml中配置nexus仓库主要考虑到这样的情侣:若在一个公司内部,同时进行多个项目,随之这几个项目都相继结束,而越来越多的项目会开始,为避免在每一个项目中都配置相同的配置文件,所以我们提供一个统一的仓库,供所有项目使用,这样就可以提高代码的复用性,避免做没有必要的无用功!
2、激活profile
3、配置镜像mirror
nexus仓库默认用户名:admin;密码:admin123
3、执行部署
如果之前没用执行过该命令,maven会自动到中央仓库中下载部署所需的插件。最后在命令行中看到如下所示就代表构件已经部署成功。
![](https://oscdn.geek-share.com/Uploads/Images/Content/201707/5fcdaba04de10200557b74c6cb8ab990)
到nexus的releases仓库中即可查看刚刚部署好的构件信息。
windows下搭建nexus仓库:http://blog.csdn.net/hh12211221/article/details/74010609
在pom文件中配置nexus仓库
<repositories> <!-- 配置nexus远程仓库 --> <repository> <id>nexus</id> <name>Nexus Snapshot Repository</name> <url>http://127.0.0.1:8088/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <!-- 配置从哪个仓库中下载构件,即jar包 --> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>Nexus Snapshot Repository</name> <url>http://127.0.0.1:8088/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories>以上在pom文件中的配置仅对当前项目有效,但若需在其他项目中使用,为避免代码重复性,减少冗余,可在settings.xml文件中配置。在setting.xml文件中不存在repositories、pluginRepositories标签,而选择使用profile,具体配置可参考一下代码。
配置setting.xml文件
setting.xml文件的位置:../apache-maven-3.3.3/conf/setting.xml。1、在setting.xml文件中配置nexus仓库,如下所示:
<profile> <id>development</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>
注:
在配置远程仓库时,中央仓库的id为central,远程url地址为http://repo.maven.apache.org/maven2。
在setting.xml中配置nexus仓库主要考虑到这样的情侣:若在一个公司内部,同时进行多个项目,随之这几个项目都相继结束,而越来越多的项目会开始,为避免在每一个项目中都配置相同的配置文件,所以我们提供一个统一的仓库,供所有项目使用,这样就可以提高代码的复用性,避免做没有必要的无用功!
2、激活profile
<activeProfiles> <activeProfile>development</activeProfile> </activeProfiles>
3、配置镜像mirror
<mirrors> <mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <name>Nexus Mirror</name> <url>http://127.0.0.1:8088/content/groups/public/</url> </mirror> </mirrors>
部署构件到nexus仓库
1、在pom文件中添加如下配置<distributionManagement> <repository> <id>archiva.releases</id> <name>Internal Releases</name> <url>http://127.0.0.1:8088/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>development</id> <name>Internal Snapshots</name> <url>http://127.0.0.1:8088/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>2、在setting.xml文件中添加认证信息
<server> <id>development</id> <username>admin</username> <password>admin23</password> </server> <server> <id> archiva.releases </id> <username> admin </username> <password>admin23</password> </server>
nexus仓库默认用户名:admin;密码:admin123
3、执行部署
<dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.14</version> </dependency>4、在命令行中执行:mvn clean deploy
如果之前没用执行过该命令,maven会自动到中央仓库中下载部署所需的插件。最后在命令行中看到如下所示就代表构件已经部署成功。
到nexus的releases仓库中即可查看刚刚部署好的构件信息。
相关文章推荐
- Maven pom.xml 配置说明: 打jar包不包括指定资源文件和.class xml,配置不跑testCase,建pom父子项目
- Maven的使用,Nexus建立本地仓库以及Eclipse导入Maven项目(三): 配置篇
- nexus-3.6.0-02-unix.tar.gz安装(Centos下),maven setting.xml配置案例,项目root的pom.xml配置,parent-pom的pom.xml配置案例
- maven构建ssm项目之pom文件配置(一)
- 在maven的pom文件中配置开源中国的中央仓库
- 使用Maven管理Mybatis项目之pom文件配置
- 创建maven项目#配置pom文件
- Java Maven项目的关键参数配置到pom文件的方法
- 让Maven项目使用Nexus作为远程仓库的settings.xml配置
- 如何在maven的pom文件中配置开源中国的中央仓库
- IDEA初使用---检出maven项目,私服仓库配置,spring配置文件映射
- MAVEN项目的配置文件pom.xml元素的含义
- MyEclipse 配置maven项目pom.xml设置 上传项目到nexus私服,通过中转仓库下载插件,以及nexus的配置
- maven搭建项目,settings.xml配置文件,以及parent的pom.xml
- maven项目继承和聚合pom文件配置
- 电商项目(十六)项目初始化(maven的pom文件配置)
- Maven将本地jar包生成pom文件,在项目中引用打包到本地仓库。
- 大型Java项目中使用maven进行管理,pom.xml文件中build的配置
- maven web项目pom.xml文件配置打包war文件
- 对于maven创建spark项目的pom.xml配置文件(图文详解)