您的位置:首页 > 其它

使用nexus为maven搭建私服

2015-01-12 11:48 513 查看
使用nexus为maven搭建私服 
1、搭建maven私服工具有很多,如artifactory、Nexus等,我们以nexus为例,介绍maven私服搭建 
2、下载nexus,http://nexus.sonatype.org/download-nexus.html,有war和zip两个可供选择, 
war下载后需要部署到一个application server中,zip包自带jetty服务器,解压后自行启动 
3、tar -zvxf nexus-oss-webapp-1.9.2.2-bundle.tar.gz, 
cd nexus-oss-webapp-1.9.2.2 
mv nexus-oss-webapp-1.9.2.2 nexus 
cd /usr/local/nexus/bin/jsw/linux-x86-64 
执行./nexus start,即可启动nexus 
4、浏览器访问http://localhost:8081/nexus/index.html,正常打开ok,未登录时,只能显示Repositories一个菜单,用默认的admin/admin123登录,左侧显示所有菜单。默认情况下私服中已经后很多jar,我们可以手工添加一些jar. 
5、选择Repositories-》3rdparty-》artifactsupload,该tab页下可以把我们本地的jar上传到私服仓库中,GAV Definition选择GAV Parameters,然后点击Select Artifact(s) to Upload..选择要上传的jar文件即可 

以上过程就是整个私服搭建的过程,剩下就是我们怎么在maven中从自己搭建的私服中下载指定的jar包,以下省略maven本地的安装过程。 
1、maven配置好后,通常会在C:\Documents and Settings\当前用户名\.m2目录下有个setting.xml文件,如果没有,可以从maven安装路径下的conf目录拷贝, 
2、在setting.xml文件的<profiles>标签中新加以下内容 
<profile> 
      <id>nexus</id> 
      <repositories> 
        <repository> 
        <id>nexus</id> 
            <name>215 private nexus</name> 
            <url>http://私服地址:8081/nexus/content/groups/public</url> 
            <releases><enabled>true</enabled></releases> 
            <snapshots><enabled>true</enabled></snapshots> 
        </repository> 
       
      </repositories> 
      <pluginRepositories> 
        <pluginRepository> 
            <id>nexus</id> 
            <name>local private nexus</name> 
            <url>http://10.10.1.215:8081/nexus/content/groups/public</url> 
            <releases><enabled>true</enabled></releases> 
            <snapshots><enabled>true</enabled></snapshots> 
        </pluginRepository>       
       </pluginRepositories> 
    </profile>  
  
    <activeProfiles> 
        <activeProfile>nexus</activeProfile> 
  </activeProfiles>   

3、在我们项目中的pom.xml文件中添加依赖的jar 
   <dependency> 
      <groupId>test_jar</groupId> 
      <artifactId>test</artifactId> 
      <version>1.3</version> 
    </dependency> 
完成以上步骤就大功告成啦!  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  maven