分享

Linux下使用Nexus做Maven仓库管理

 richsky 2013-10-29

一:JDK

1.Installation

  • Download the lasted version of the JDK from: http://java. ,now is JDK1.7.0_10.
  • Unpack the arcive to /usr/lib/jvm/java with the below command line:

         tar -zxvf jdk-7u10-linux-i586.tar.gz

2. Set java environment variable

# vi /etc/profile

# This is added by selina for set java environment:

JAVA_HOME=/usr/lib/jvm/java/jdk1.7.0_10

JRE_HOME=/usr/lib/jvm/java/jdk1.7.0_10/jre

export JAVA_HOME

export JRE_HOME

export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH

# end of set java environmnet

save and exit.

# source /etc/profile //with immediate effect

# java -version or echo $JAVA_HOME

check whether take effect :logout then

# java -version or echo $JAVA_HOME

 

二:Maven

1.Installation

  • Download the lasted version of the Maven from http://maven./download.html ,now is 3.0.4 .
  • Unapack the archive to /usr/local with beow the command line :
  •        tar -zxvf  apache-maven-3.0.4-bin.tar.gz
  • rename apache-maven-3.0.as maven3
  •      mv apache-maven-3.0.4 maven3

2.Set Maven environment variable

# vi /etc/profile

 # This is added by selina for set Maven environment:

MAVEN_HOME=/usr/local/maven3

export MAVEN_HOME

export PATH=$MAVEN_HOME/bin:$PATH

# end of set java environmnet

save and exit.

# source /etc/profile //with immediate effect

mvn -v or echo $MAVEN_HOME

check whether take effect :logout then

# mvn -v or echo $MAVEN_HOME

Note that if you use "mvn -v" to see ,will show maven and jave version info indicate that successfully installed and configured.

 

三:Nexus

1.Installation

Download the lasted version of the Nexus from http://nexus./downloads/ ,now is nexus-2.2-01.

Unpack the archive to /usr/local with the below command line

   tar -zxvf nexus-2.2-01-bundle.tar.gz

and remane to nexus2 with the below command line

   mv nexus-2.2-01-bundle nexus2

2. Run Nexus

$ cd /usr/local/nexus2/bin/jsw/linux-x86-32

$ ./nexus start (restart/stop...) # use ordinary account not root

if successd ,Go to browser http://ip:8081/nexus ,account and passowd is admin and admin123

(if you want to change port number ,pls go to ./nexus2/conf/nexus.properties to set ,the default is 8081)

issues:

(1)if successfully installed ,will show :

       Starting Nexus OSS...

      Stared Nexus OSS

But ,after installing nexus ,excute command "./nexus start" failed ,show the below message:

       Starting Nexus OSS...

      Failed to start Nexus OSS.

Solution : this is casued by priviledge of nexus directory ,it belongs to root user .After change the owner of the nexus directory to the current user ,rerun the command "./nexus start",it works.

sudo chown -R selina:selina ../../nexus

(2)Can't browser

when http://ip:8081/nexus ,failed ,need to see log message from: ./nexus/logs/wrapper.log ,show "Unable to start JVM: No such file or directory" in here ,

Solution : editing "<nexus_root>/bin/jsw/conf/wrapper.conf" and changing "wrapper.java.commad" the full path to my java executable

wrapper.java.commad={JAVA_HOME}/bin/java

Again to http://ip:8081/nexus ,failed ,see log message ,show " error..Temp directory:/usr/lcoal/sonatype-work/nexus/tmp "

Solution : chmod -R 777 /usr/local/sonatype-work/nexus/tmp

 

 Congratulations ,well done.Click the "Login In" on the top right corner.the default username is admin ,password is admin123.Linux下使用Nexus做Maven仓库管理

登录后最重要的事情就是打开远程索引下载,操作为选择菜单Administrator->Repositories,然后在右边打开的列表中依次选择type字段为proxy的记录,在下方的编辑区中修改"Download Remote Indexes"值为true,再从这三个仓库上点右键选择"Reapir Index",这一步别忘,Repair Index后,Nexus会从后台去官方地址下载仓库索引文件,大概20M大小,根据网速快慢下载相应时间后选择仓库时会以树形目录的方式显示仓库内容。(注意:如果repaire-index后,在“browser index"里仍然看不到东西,要确定/usr/lcoal/sonatype-work/nexus目录是否有写权限 )Central的"Remote storage location"默认的是http://repo1./maven2,因这是国外网站,忒慢,如此找到了以下这个源镜像:http://repo.maven./maven2Linux下使用Nexus做Maven仓库管理想要maven使用刚刚配置的nexus服务作为仓库服务器需要修改settings.xml文件。

在maven中存在两个 settings.xml,一个位于maven2的安装目录conf下面,作为全局性配置。对于团队设置,保持一致的定义是关键,所以 maven/conf下面的settings.xml就作为团队共同的配置文件。保证所有的团队成员都拥有相同的配置。当然对于每个成员,都需要特殊的 自定义设置,如用户信息,所以另外一个settings.xml就作为本地配置。默认的位置为:${HOME} /.m2/settings.xml目录
 

<settings> 
<!--<localRepository>这个是存放eclipse项目需要费用的jar包(在eclipse项目添加maven依赖的时候,eclipse自动从nexus服务器中下载jar包,然后存到这个路径,默认路径是~/.m2/repository,可以不修改-->
  <localRepository>/resource/java/repos/maven-repo</localRepository>

<servers> 
      <server> 
         <!-- 这是server的id(注意不是用户登陆的id),该id与pom.xml 中distributionManagement中repository元素的id相匹配。--> 
         <!--远程nexus 服务器的用户名与密码,作用就是当要向nexus deploy 自已写的jar 时,会用到在pom.xml 中distributionManagement ,在那里会引用此处的id --> 
         <id>releases</id> 
         <username>admin</username> 
         <password>admin123</password> 
</server>
 <server> 
         <id>snapshots</id> 
         <username>admin</username> 
         <password>admin123</password> 
</server>
</servers> 

<mirrors>
<mirror>
      <!--This sends everything else to /public -->
     <!--该镜像的唯一标识符。id用来区分不同的mirror元素。 -->
     
      <id>nexus</id>
      <!--该镜像的URL。构建系统会优先考虑使用该URL,而非使用默认的服务器URL --> 
      <url>http://localhost:8081/nexus/content/groups/public</url>
      <!--被镜像的服务器的id。例如,如果我们要设置了一个Maven中央仓库http://repo1./maven2)的镜像,就需要将该元素设置成central。这必须和中央仓库的id central完全一致。 --> 
            <mirrorOf>central</mirrorOf> 

 </mirror>
</mirrors>

<profiles>
<!--个性配置。类似于pom.xml中的profile元素。单独定义profile后,并不会生效,需要通过满足条件来激活-->
<profile>
     <!--该配置的唯一标识符。 -->  
     <id>development</id>  
      <repositories>  
         <!--包含需要连接到远程仓库的信息 -->       
         <repository>
            <!--远程仓库唯一标识-->          
            <id>central</id>          
            <name>local private nexus</name>             
           <url>http://127.0.0.1:8081/nexus/content/groups/public</url>                     
             <!--如何处理远程仓库里发布版本的下载-->            
             <releases><enabled>true</enabled></releases>
             <snapshots><enabled>false</enabled></snapshots>
        </repository>     
      </repositories>    
      <pluginRepositories>   
        <pluginRepository>        
           <id>central</id>           
           <name>local private nexus</name>     
           <url>http://127.0.0.1:8081/nexus/content/groups/public</url>                                      <releases><enabled>true</enabled></releases>         
           <snapshots><enabled>false</enabled></snapshots>      
       </pluginRepository>   
    </pluginRepositories>
</profile>
</profiles>
<activeProfiles>
    <activeProfile>development</activeProfile>
</activeProfiles>
</settings>


然后,在从你的工程里的pom.xml中加入以下内容:

 
<distributionManagement>
 <repository>
<!--ID要与maven中的setting.xml中的ID一致-->
  <id>releases</id>
  <name>Nexus Release Repo</name>
  <url>http://localhost:8081/nexus/content/repositories/releases</url>
 </repository>
 <snapshotRepository>
<!--ID要与maven中的setting.xml中的ID一致-->
  <id>snapshots</id>
  <name>snapshots</name>
  <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
 </snapshotRepository>
</distributionManagement>


网络其它好文章链接:http://my.oschina.net/aiguozhe/blog/101537 

  

 

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多