`
lanhuidong
  • 浏览: 223558 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

配置自己的maven库——nexus

阅读更多

用maven管理项目时,如果某人加入了maven中心库无法下载到的依赖包,则其他人同步代码后整个项目会报错,我们可以配置一个自己的maven库来解决这个问题。http://maven.apache.org/repository-management.html推荐了几个可用于配置maven库的软件,比如Apache Archiva,Artifactory。本文将选择nexus来配置一个maven库。

 

操作系统为64位Centos 6.3

 

1.从http://www.sonatype.org/nexus/go下载nexus-2.3.0-04.zip或者nexus-2.3.0-04-bundle.tar.gz

nexus-2.3.0-04.zip解压之后放入Tomcat等web容器中即可,下面介绍nexus-2.3.0-04-bundle.tar.gz配置。

2.下面命令最好不要用root帐号操作,因为nexus不推荐用root帐号启动,而目录拥有者和启动帐号不一致会有其他问题产生

3.解压下载的文件到安装目录,比如:/usr/local,tar -zxf nexus-2.3.0-04-bundle.tar.gz

4.进入解压目录,chmod -R a+x bin

5.启动nexus,bin/jsw/linux-x86-64/nexus start

6.启动nexus的帐号对sonatype-work(和nexus-2.3.0-04目录同级)目录要有读写权限

7.在浏览器输入http://ip:8081/nexus,在页面右上角有登录连接,默认账户是admin,密码admin123(注意防火墙是否允许访问8081接口)



 

 

8.点击Repositories将会看到如下界面,其中红色框的三个库是我们配置自己maven的主要原因

 

 

9.首先上传一个第三方的包(淘宝sdk),按下图提示填入后upload即可

 
 
 
 

10.然后我们把自己的项目安装到这个库中,首先需要配置settings.xml

<server> 
      <id>inexus</id> 
      <username>admin</username>
      <password>admin123</password>
</server> 

 

然后在项目的pom.xml文件中加入如下xml片段

<distributionManagement> 
      <repository> 
            <id>inexus</id> 
            <name>Release</name>
            <url>http://192.168.202.129:8081/nexus/content/repositories/releases/</url> </repository> 
      <snapshotRepository> 
            <id>inexus</id> 
            <name>Snapshots</name>
            <url>http://192.168.202.129:8081/nexus/content/repositories/snapshots/</url> 
      </snapshotRepository> 
</distributionManagement> 

  然后使用mvn:deploy命令即可将项目安装到maven库中

 

11.从自己的maven库获取依赖包,配置settings.xml文件,其中profile片段可以放到项目的pom.xml中

<profile> 
      <id>nexus</id> 
      <repositories> 
            <repository> 
            <id>inexus</id>
            <url>http://192.168.202.129:8081/nexus/content/groups/public/</url> 
            <releases> 
                  <enabled>true</enabled> 
            </releases> 
            <snapshots> 
                  <enabled>true</enabled> 
            </snapshots> </repository>   
      </repositories> 
</profile> 
<activeProfiles> 
      <activeProfile>nexus</activeProfile> 
</activeProfiles> 

 

12.当有web的项目时, 如果maven-war-plugin过低时发布会报错

<plugin> 
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <version>2.3</version> 
</plugin>

 

 

 

  • 大小: 54.3 KB
  • 大小: 59.2 KB
  • 大小: 47.6 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics