maven项目配置时私服nexus以及仓库repository的一些情况

来源:互联网 发布:a5网站源码 编辑:程序博客网 时间:2024/04/27 16:23

前几日碰到了一个项目,主要是基于一个开源项目的二次开发,

主项目的pom.xml有如下代码段

<!-- 设定除中央仓库(repo1.maven.org/maven2/)外的其他仓库,按设定顺序进行查找. --><repositories><!-- 如有Nexus私服, 取消注释并指向正确的服务器地址. <repository> <id>nexus-repos</id> <name>Team Nexus Repository</name> <url>http://localhost:8081/nexus/content/groups/public</url> </repository> --> <repository><id>central-repos</id><name>Central Repository</name><url>http://repo.maven.apache.org/maven2</url><snapshots><enabled>false</enabled></snapshots></repository><repository><id>springsource-repos</id><name>SpringSource Repository</name><url>http://repo.springsource.org/libs-milestone-local</url><snapshots><enabled>false</enabled></snapshots></repository>
这里就是为了防止私服中央仓库没有找到jar的时候需要本地直接去springsource-repos引用仓库寻找。

这里可以把这里面的一些仓库repostory的url在nexus中进行设置。

1.添加proxy repository。然后设置相应的id,name,以及url。

2.然后添加需要使用到的repository到 public group中,如下 

设置好之后进行刷新

查看

是否有这样的  remoxxxx。就是被阻塞了。这个时候 这个repository就要在pom.xml文件中进行配置了。

---------------------------------------------------------------------------------------------------------------------------------------

这时候要配置maven的镜像。

打开maven安装目录下的conf-----》settings.xml文件。

 <mirrors>   <mirror>      <id>central</id>      <mirrorOf>*</mirrorOf>      <name>Human Readable Name for this Mirror.</name>      <url>http://localhost:8081/nexus/content/groups/public/</url>    </mirror>

xxx

下面还要配置一个

<profiles>     <profile>     <id>central-repos</id>      <repositories>        <repository>          <id>central</id>          <name>central_nexus</name>          <url>http://localhost:8081/nexus/content/groups/public/</url>          <layout>default</layout>          <snapshotPolicy>always</snapshotPolicy>        </repository>      </repositories>    </profile>
然后要启动这个profile。

<activeProfiles>    <activeProfile>central-repos</activeProfile>  </activeProfiles>  <!-- activeProfiles   | List of profiles that are active for all builds.   |  <activeProfiles>
这样就可以使用了。具体这个配置还是参考孔浩老师的maven配置吧。

另外记得配置用户名和密码,一般使用admin和admin123就可以了。

 <server>      <id>test-log-snapshot</id>      <username>deployment</username>      <password>deployment123</password>    </server><server>      <id>user-releases</id>      <username>deployment</username>      <password>deployment123</password>    </server><server>      <id>user-snapshots</id>       <username>deployment</username>      <password>deployment123</password>    </server>

这里把上面的改成admin和admin123吧。具体忘了。。。。。╮(╯▽╰)╭ 

然后一直重启eclipse,update  maven项目。

看下可以否。。。