使用nexus在局域網內搭建maven私服及idea的使用

一:JDKhtml

1.Installationjava

  • Download the lasted version of the JDK from: http://java.sun.com ,now is JDK1.7.0_10.linux

  • Unpack the arcive to /usr/lib/jvm/java with the below command line:apache

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

2. Set java environment variable服務器

# vi /etc/profileapp

# This is added by selina for set java environment:eclipse

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

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

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.apache.org/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.4 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.sonatype.org/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/

$ ./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倉庫管理
 

注意:Nexus 不能使用root用戶啓動,須要使用普通用戶啓動,假設普通用戶爲user,則須要:

chown -R user:user nexus2

chown -R user:user sonatype-work

登陸後最重要的事情就是打開遠程索引下載,操做爲選擇菜單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.maven.org/maven2,因這是國外網站,忒慢,如此找到了如下這個源鏡像:http://repo.maven.apache.org/maven2

想要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.maven.org/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://localhost:8081/nexus/ 啓動後以下頁面,在右上角有個Log in 的超連接,點擊登陸

默認的用戶名是 admin 密碼是 admin123

 

Public Repositories:  倉庫組

3rd party: 沒法從公共倉庫得到的第三方發佈版本的構件倉庫

Apache Snapshots: 用了代理ApacheMaven倉庫快照版本的構件倉庫

Central: 用來代理maven中央倉庫中發佈版本構件的倉庫

Central M1 shadow: 用於提供中央倉庫中M1格式的發佈版本的構件鏡像倉庫

Releases: 用來部署管理內部的發佈版本構件的宿主類型倉庫

Snapshots:用來部署管理內部的快照版本構件的宿主類型倉庫

配置Public Repositories屬性,在Ordered Group Repositories中將倉庫都選中。

 

二  IntelliJ IDE使用私服配置

方法一:

找到maven的安裝目錄 D:\JetBrains\IntelliJ IDEA 14.1.5\plugins\maven\lib\maven3\conf

修改setting.xml 添加以下:

<mirrors>
    <mirror>
          <id>central</id>
          <mirrorOf>*</mirrorOf>
          <name>Central Repository</name>
          <url>http://192.168.1.7:8081/nexus/content/groups/public/</url>
      </mirror>
</mirrors>

修改 工程設置,必定要把user setting file  鉤給勾上 .  OK 工程無需其它配置 就可使用私服了


方法二:

在項目的pom.xml中添加:

<repositories>
        <repository>
            <id>public</id>
            <name>Public Repositories</name>
            <url>http://ip:8081/nexus/content/groups/public</url>
        </repository>
 </repositories>
 <pluginRepositories>
        <pluginRepository>
            <id>public</id>
            <name>Public Repositories</name>
            <url>http://ip:8081/nexus/content/groups/public</url>
        </pluginRepository>
 </pluginRepositories>

三上傳構建到私服  

 

直接用  idea  中的  deploy按鈕就能夠將 打好的 jar 包或者 war包上傳到 私服中  (install  是將jar包 拷貝到本地倉庫)

maven setting.xml 添加以下配置:

<servers>   
      <server>
          <id>nexus-releases</id>
          <username>admin</username>
          <password>admin123</password>
      </server>
      <server>
          <id>nexus-snapshots</id>
          <username>admin</username>
          <password>admin123</password>
      </server>

  </servers>

工程pom.xml 添加以下配置:

<distributionManagement>
        <repository>
            <id>nexus-releases</id>
            <name>Nexus Release Repository</name>
            <url>http://192.168.1.7:8081/nexus/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <name>Nexus Snapshot Repository</name>
            <url>http://192.168.1.7:8081/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
</distributionManagement>
相關文章
相關標籤/搜索