maven 配置nexus私服

来源:互联网 发布:红警找矿软件 编辑:程序博客网 时间:2024/05/21 22:53

一.安装

1.从nexus官网下载nexus-2.12.0-01-bundle.zip,并解压文件放到指定的目录

2.配置nexus环境变量。新建变量:NEXUS_HOME 变量值:D:\Program Files\nexus-2.12.0-01-bundle

3.编辑path,在path路径的后面加上;%NEXUS_HOME%\bin

4.在D:\Program Files\nexus-2.12.0-01-bundle\bin\jsw\windows-x86-64目录下,点击install-nexus 。注:jsw目录下根据自己电脑选择相应的目录

4.启动nexus服务.点击start-nexus启动nexus服务,stop-nexus结束服务

5.在浏览器中打开localhost:8081\nexus,界面如下图:

二.使用

1.在pom.xml中,配置如下代码

<!-- 仓库地址 -->  <repositories>    <repository>      <id>local_nexus</id>      <name>local_nexus</name>      <url>http://localhost:8081/nexus/content/groups/public</url>      <releases><enabled>true</enabled></releases>      <snapshots><enabled>true</enabled></snapshots>    </repository>  </repositories>  <!-- 插件地址 -->  <pluginRepositories>    <pluginRepository>      <id>local_nexus</id>      <name>local_nexus</name>      <url>http://localhost:8081/nexus/content/public</url>      <releases><enabled>true</enabled></releases>      <snapshots><enabled>true</enabled></snapshots>    </pluginRepository>  </pluginRepositories>
就可以从nexus服务器中下载相应的依赖包。

2.在pom.xml文件中配置如下代码:

<distributionManagement>    <repository>      <id>local_nexus_releases</id>      <name>core Release Repository</name>      <url>http://localhost:8081/nexus/content/repositories/releases</url>    </repository>    <snapshotRepository>      <id>local_nexus_snapshots</id>      <name>core Snapshots Repository</name>      <url>http://localhost:8081/nexus/content/repositories/snapshots</url>    </snapshotRepository>  </distributionManagement>
setting.xml中配置:

<server>  <id>local_nexus_releases</id>  <username>admin</username>  <password>admin123</password>     </server>     <server>  <id>local_nexus_snapshots</id>  <username>admin</username>  <password>admin123</password>     </server>  
可以把本地的jar包通过命令部署nexus服务上。

3.以上的可以在setting.xml中的profiles 和activProfiles配置如下内容:

<span style="white-space:pre"></span><profile><span style="white-space:pre"></span><id>local_nexus</id><span style="white-space:pre"></span><repositories><span style="white-space:pre"></span><repository><span style="white-space:pre"></span><id>local_nexus</id><span style="white-space:pre"></span><name>local_nexus</name><span style="white-space:pre"></span><url>http://localhost:8081/nexus/content/groups/public/</url><span style="white-space:pre"></span><releases><span style="white-space:pre"></span><enabled>true</enabled><span style="white-space:pre"></span></releases><span style="white-space:pre"></span><snapshots><span style="white-space:pre"></span><enabled>true</enabled><span style="white-space:pre"></span></snapshots><span style="white-space:pre"></span></repository><span style="white-space:pre"></span><repository><span style="white-space:pre"></span><id>central</id><span style="white-space:pre"></span><url>http://repo.maven.apache.org/maven2</url><span style="white-space:pre"></span><releases><span style="white-space:pre"></span><enabled>true</enabled><span style="white-space:pre"></span></releases><span style="white-space:pre"></span><snapshots><span style="white-space:pre"></span><enabled>true</enabled><span style="white-space:pre"></span></snapshots><span style="white-space:pre"></span></repository><span style="white-space:pre"></span></repositories><span style="white-space:pre"></span><pluginRepositories><span style="white-space:pre"></span><pluginRepository><span style="white-space:pre"></span><id>local_nexus</id><span style="white-space:pre"></span><name>local_nexus</name><span style="white-space:pre"></span><url>http://localhost:8081/nexus/content/groups/public/</url><span style="white-space:pre"></span><releases><span style="white-space:pre"></span><enabled>true</enabled><span style="white-space:pre"></span></releases><span style="white-space:pre"></span><snapshots><span style="white-space:pre"></span><enabled>true</enabled><span style="white-space:pre"></span></snapshots><span style="white-space:pre"></span></pluginRepository><span style="white-space:pre"></span><pluginRepository><span style="white-space:pre"></span><id>central</id><span style="white-space:pre"></span><url>http://repo.maven.apache.org/maven2</url><span style="white-space:pre"></span><releases><span style="white-space:pre"></span><enabled>true</enabled><span style="white-space:pre"></span></releases><span style="white-space:pre"></span><snapshots><span style="white-space:pre"></span><enabled>true</enabled><span style="white-space:pre"></span></snapshots><span style="white-space:pre"></span></pluginRepository><span style="white-space:pre"></span></pluginRepositories></profile>

<activeProfiles><activeProfile>local_nexus</activeProfile></activeProfiles>


同样可以实现1.2中功能,只是1.2中是针对某一个maven工程,而setting 文件所有的maven项目都适用


0 0
原创粉丝点击