Linux 安裝配置maven3.0 以及搭建nexus私服

1、軟件準備
一、apache-maven-3.0-bin.tar.gz 下載地址: http://www.apache.org/dyn/closer.cgi/maven/binaries/apache-maven-3.0-bin.tar.gz
二、nexus-oss-webapp-1.8.0-bundle.tar.gz 下載地址: http://nexus.sonatype.org/downloads/

2、maven安裝配置
一、建立須要操做maven的用戶組以及用戶(若是用root用戶安裝不用建立)
Java代碼   收藏代碼
  1. #groupadd configer  //建立用戶組  
  2. #useradd -g configer configer  //建立用戶並指定用戶組  
  3. #passwd configer  //爲用戶分配密碼  

二、建立解壓目錄,並將apache-maven-3.0-bin.tar.gz文件解壓到指定目錄

Java代碼   收藏代碼
  1. #cd /opt  
  2. #mkdir maven  
  3. #chown -R configer:configer /opt/maven  
  4. #chmod 755 /opt/maven  
  5. #su -l configer  
  6. #tar -zvxf apache-maven-3.0-bin.tar.gz  


二、配置環境變量
Java代碼   收藏代碼
  1. #vi /home/configer/.bash_profile  

在文件中添加以下行:
Java代碼   收藏代碼
  1. M2_HOME=/opt/maven/apache-maven-3.0  
  2. export M2_HOME  
  3. PATH=$PATH:$M2_HOME/bin  
  4. export PATH  


三、查看版本
Java代碼   收藏代碼
  1. #cd /opt/maven/apache-maven-3.0/bin  
  2. #mvn --version  

若是顯示版本信息,應該會在${user}目錄下建立.m2目錄

四、查看.m2目錄
Java代碼   收藏代碼
  1. #cd /home/configer/.m2  
  2. 若是沒有.m2目錄,則能夠手動添加一個  
  3. #mkdir .m2  


五、若是須要把maven的repository目錄指定到其餘目錄,則修改maven安裝目錄下conf中的配置文件settings.xml文件
Java代碼   收藏代碼
  1. #vi /opt/maven/apache-maven-3.0/conf/settings.xml  
  2. 將文件中<localRepository>....</localRepository>的註釋打開  
  3. 或者在文件中增長 在這個註釋下增長  
  4. <localRepository>your repository path</localRepository>  



2、搭建nexus私服
一、解壓nexus-oss-webapp-1.8.0-bundle.tar.gz文件到指定目錄
Java代碼   收藏代碼
  1. #tar -zvxf nexus-oss-webapp-1.8.0-bundle.tar.gz  


二、啓動nexus
Java代碼   收藏代碼
  1. #cd /opt/maven/nexus-oss-webapp-1.8.0/bin/jsw  
  2.   
  3. 選擇本身機器的版本:  
  4.   
  5. #cd linux-x86-32/  
  6. #./nexus start  
  7.   
  8. 重啓:  
  9. #./nexus restart  
  10. 中止:  
  11. #./nexus stop  


三、運行nexus
在瀏覽器中輸入:http://localhost:8081/nexus
就能夠看到nexus 的主頁,點擊右上角Log in
默認用戶名和密碼是:admin/admin123
運行後會自動生成一個nexus工做目錄sonatype-work,nexus下載的jar包會存放在
sonatype-work/nexus/storage中

四、配置
1)點擊左側菜單Repositories
分別將右側列表中
Java代碼   收藏代碼
  1. Apache Snapshots  
  2. Codehaus Snapshots  
  3. Maven Central  

三個repository 的Download Remote Index 配置改成True,並保存設置,
而後在列表中分別右鍵點擊三個Repository,點擊ReIndex

2)增長新的Repository,有一些比較經常使用jar包在nexus提供的repository中可能找不到,
通常比較經常使用的有
Java代碼   收藏代碼
  1. JBOSS的兩個:  
  2. http://repository.jboss.org/maven2/  
  3. http://repository.jboss.org/nexus/content/repositories/releases/  
  4. SUN的:  
  5. http://download.java.net/maven/2/  
  6. K-INT的:  
  7. http://developer.k-int.com/maven2/  
  8.   
  9. 由於找juel:juel-impl:2.2.1 這個jar包,因此我還添加了一個本身找的:  
  10. http://repository.exoplatform.org/content/groups/public/  


添加步驟:
Java代碼   收藏代碼
  1. 點擊Add->Proxy Repository->填寫Repository ID, Repository Name, 以及Remote Storage Location 其餘的默認便可。  


3) 將新增的Repository添加到Public Repositories中
在Public Repositories 的Configuration中,將多選Select中的項所有添加到左邊,而後保存。

4) 添加本身的jar包
Java代碼   收藏代碼
  1. 在repository列表中有一個3rd party,也就是第三方jar包,點擊會看到一個Artifact Upload選項卡,點擊後,填寫相應的信息。  
  2. GAV Definition 通常選擇 GAV Parameters  
  3. 而後添加Group:Artifact:Version:Package  
  4. 示例    juel:juel-impl:2.2.1:jar  


而後選擇要上傳的jar包,保存便可

5) nexus中設置代理服務器
選擇左側administrator菜單中的Server選項,在右側打開的頁面的中下部,有一個選擇項:Default HTTP Proxy Settings(optional) 將複選框選中,填寫相應的代理服務器信息便可。

6) 編寫本身的settings.xml,文件內容以下:
Java代碼   收藏代碼
  1. <settings>  
  2.   <proxies>  
  3.     <proxy>  
  4.       <id>normal</id>  
  5.       <active>true</active>  
  6.       <protocol>http</protocol>  
  7.       <username>deployment</username>  
  8.       <password>deploy</password>  
  9.       <host>localhost:8081/nexus</host>  
  10.       <port>80</port>  
  11.       <nonProxyHosts>localhost:8081/nexus</nonProxyHosts>  
  12.     </proxy>  
  13.   </proxies>  
  14.   
  15.   <mirrors>  
  16.     <mirror>  
  17.       <!--This is used to direct the public snapshots repo in the   
  18.           profile below over to a different nexus group -->  
  19.       <id>nexus-public-snapshots</id>  
  20.       <mirrorOf>public-snapshots</mirrorOf>  
  21.       <url>http://localhost:8081/nexus/content/groups/public-snapshots</url>  
  22.     </mirror>  
  23.     <mirror>  
  24.       <!--This sends everything else to /public -->  
  25.       <id>nexus</id>  
  26.       <mirrorOf>*</mirrorOf>  
  27.       <url>http://localhost:8081/nexus/content/groups/public</url>  
  28.     </mirror>  
  29.   </mirrors>  
  30.     
  31.   <profiles>  
  32.     <profile>  
  33.       <id>development</id>  
  34.       <repositories>  
  35.         <repository>  
  36.           <id>central</id>  
  37.           <url>http://central</url>  
  38.           <releases><enabled>true</enabled></releases>  
  39.           <snapshots><enabled>true</enabled></snapshots>  
  40.         </repository>  
  41.       </repositories>  
  42.      <pluginRepositories>  
  43.         <pluginRepository>  
  44.           <id>central</id>  
  45.           <url>http://central</url>  
  46.           <releases><enabled>true</enabled></releases>  
  47.           <snapshots><enabled>true</enabled></snapshots>  
  48.         </pluginRepository>  
  49.       </pluginRepositories>  
  50.     </profile>  
  51.     <profile>  
  52.       <!--this profile will allow snapshots to be searched when activated-->  
  53.       <id>public-snapshots</id>  
  54.       <repositories>  
  55.         <repository>  
  56.           <id>public-snapshots</id>  
  57.           <url>http://public-snapshots</url>  
  58.           <releases><enabled>false</enabled></releases>  
  59.           <snapshots><enabled>true</enabled></snapshots>  
  60.         </repository>  
  61.       </repositories>  
  62.      <pluginRepositories>  
  63.         <pluginRepository>  
  64.           <id>public-snapshots</id>  
  65.           <url>http://public-snapshots</url>  
  66.           <releases><enabled>false</enabled></releases>  
  67.           <snapshots><enabled>true</enabled></snapshots>  
  68.         </pluginRepository>  
  69.       </pluginRepositories>  
  70.     </profile>  
  71.   </profiles>  
  72.   <activeProfiles>  
  73.     <activeProfile>development</activeProfile>  
  74.   </activeProfiles>  
  75. </settings>  

將settings.xml文件複製到${user}/.m2目錄下

7) 測試
建立一個maven項目
Java代碼   收藏代碼
  1. #mvn archetype:generate  

若是建立一個web項目能夠選擇83
填寫相應的信息,maven會從私服上下載相應的jar包,看到的地址應該都是localhost的
項目建立成功後,將本身的pom.xml文件放在項目,執行
Java代碼   收藏代碼
  1. #mvn install 或者#mvn package
mvn會下載pom.xml文件定義的jar依賴 下載完成後,你能夠在本身指定的repository目錄下,若是沒有指定則是在.m2/repository目錄下查看本身的jar包 至此,咱們的maven安裝以及私服的搭建工做就完成了。
相關文章
相關標籤/搜索