maven nexus 搭建


http://lichunlong0630.iteye.com/blog/897198

http://192.168.1.107:8081/nexus/index.html#welcome

 

用Nexus來搭建本地的Maven服務器

下載地址是:http://nexus.sonatype.org/downloads/ 

我下載的是:nexus-oss-webapp-1.8.0.1-bundle.tar.gz

 

一、安裝服務器

 

解壓下載的文件:

 

# tar xzvf nexus-oss-webapp-1.8.0.1-bundle.tar.gz

 

解壓后目錄:

 

nexus-oss-webapp-1.8.0.1 包含了nexus的運行環境和應用程序

 

sonatype-work 包含了你自己的配置和數據

 

啟動nexus

 

進入nexus-oss-webapp-1.8.1目錄

 

# cd nexus-oss-webapp-1.8.0.1/bin/jsw

 

根據自己機器選擇版本

 

 

我選擇的是 linux-x86-32

 

# cd linux-x86-32/

 

linux-x86-32目錄結構 :lib  nexus  nexus.pid  platform.conf  wrapper

 

nexus就是啟動命令

 

# ./nexus

 

執行上面的命令,可以得到nexus命令的用法提示:start 命令啟動,stop命令停止。下面啟動nexus:

 

# ./nexus start

 

 

以上表示啟動成功!

 

通過log文件查看更詳細的信息

 

# cd ~/nexus-oss-webapp-1.8.0.1/log

 

# tail -f wrapper.log

 

在log中可以看到nexus默認監聽的端口是8081。那么我們就可以在瀏覽器中訪問:http://host:8081/nexus

 

默認用戶名是admin密碼是admin123

 

 

二、配置Nexus

 

由於在新搭建的nexus環境中只是一個空的倉庫,所以第一步就是要和遠程的Maven中心倉庫進行同步。

 

 

 

 

如果在Reindex之后,並沒有同步到遠程的倉庫,可以檢查每個倉庫的設置。下面是Maven Central的設置:

 

 

 

 三、在項目中使用私服

 

在完成了上面的配置后,就可以將項目中默認的Repository切換為本地的私服了,只需要在pom.xml中增加repositories就可以了:

 

Java代碼    收藏代碼
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  3.   <modelVersion>4.0.0</modelVersion>  
  4.   
  5.   <groupId>com.mycom.test</groupId>  
  6.   <artifactId>simple</artifactId>  
  7.   <version>0.0.1-SNAPSHOT</version>  
  8.   <packaging>jar</packaging>  
  9.   
  10.   <name>simple</name>  
  11.   <url>http://maven.apache.org</url>  
  12.   
  13.   <repositories>    
  14.     <repository>    
  15.       <snapshots>    
  16.         <enabled>true</enabled>    
  17.       </snapshots>    
  18.       <id>public</id>    
  19.       <name>Public Repositories</name>    
  20.       <url>http://192.168.1.7:8081/nexus/content/groups/public/</url>    
  21.     </repository>    
  22.   </repositories>  
  23.   <pluginRepositories>    
  24.     <pluginRepository>    
  25.       <id>public</id>    
  26.       <name>Public Repositories</name>    
  27.       <url>http://192.168.1.7:8081/nexus/content/groups/public//</url>    
  28.     </pluginRepository>    
  29.   </pluginRepositories>    
  30.   <properties>  
  31.     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  32.   </properties>  
  33.   
  34.   <dependencies>  
  35.     <dependency>  
  36.       <groupId>junit</groupId>  
  37.       <artifactId>junit</artifactId>  
  38.       <version>3.8.1</version>  
  39.       <scope>test</scope>  
  40.     </dependency>  
  41.   </dependencies>  
  42. </project>  
 

將pom.xml保存后,再回過頭來了看去nexus管理界面看,就會發現junit已經被下載到本地的nexus服務器中了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM