Nexus配置内部仓库

http://blog.csdn.net/gl74gs48/article/details/7721758

关于创建Nexus不想多说,到官方网站http://www.sonatype.org/nexus下载WAR,直接在TOMCAT下发布就OK了。具体记录怎样配置Maven使用Nexus作为内部库,官方有一篇文章《Configuring Maven to Use a Single Nexus Group》

If you are adopting Nexus for internal development you should configure a single Nexus group which contains both releases and snapshots. To do this, add snapshot repositories to your public group, and add the following mirror configuration to your Maven settings in ~/.m2/settings.xml

  1. <SPAN style="FONT-SIZE: 12px"><settings>  
  2.   <mirrors>  
  3.     <mirror>  
  4.       <!--This sends everything else to /public -->  
  5.       <id>nexus</id>  
  6.       <mirrorOf>*</mirrorOf>  
  7.       <url>http://localhost:8081/nexus/content/groups/public</url>  
  8.     </mirror>  
  9.   </mirrors>  
  10.   <profiles>  
  11.     <profile>  
  12.       <id>nexus</id>  
  13.       <!--Enable snapshots for the built in central repo to direct -->  
  14.       <!--all requests to nexus via the mirror -->  
  15.       <repositories>  
  16.         <repository>  
  17.           <id>central</id>  
  18.           <url>http://central</url>  
  19.           <releases><enabled>true</enabled></releases>  
  20.           <snapshots><enabled>true</enabled></snapshots>  
  21.         </repository>  
  22.       </repositories>  
  23.      <pluginRepositories>  
  24.         <pluginRepository>  
  25.           <id>central</id>  
  26.           <url>http://central</url>  
  27.           <releases><enabled>true</enabled></releases>  
  28.           <snapshots><enabled>true</enabled></snapshots>  
  29.         </pluginRepository>  
  30.       </pluginRepositories>  
  31.     </profile>  
  32.   </profiles>  
  33.   <activeProfiles>  
  34.     <!--make the profile active all the time -->  
  35.     <activeProfile>nexus</activeProfile>  
  36.   </activeProfiles>  
  37. </settings>  
  38. </SPAN>  
<settings>
  <mirrors>
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:8081/nexus/content/groups/public</url>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>


 In Configuring Maven to Use a Single Nexus Group we have defined a single profile: nexus profile is configured to download from the central repository with a bogus URL. This URL is overridden by the mirror setting in the same settings.xml file to point to the URL of your single Nexus group. The nexus group is then listed as an active profile in the activeProfiles element.

配置完成后,使用mv package命令出错,提示:
org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved

最后不断尝试,发现将<mirror>节点的<id>的值改为central,package命令成功执行。而且发现无须配置<profiles>,依然可以执行成功。

settings.xml最终配置如下:

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"   
  4.           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  5.           xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">  
  6.   <!-- localRepository  
  7.    | The path to the local repository maven will use to store artifacts.  
  8.    |  
  9.    | Default: ~/.m2/repository  
  10.   <localRepository>C:/apache-maven-3.0.4/repository</localRepository>  
  11.   -->  
  12.   
  13.   <!-- interactiveMode  
  14.    | This will determine whether maven prompts you when it needs input. If set to false,  
  15.    | maven will use a sensible default value, perhaps based on some other setting, for  
  16.    | the parameter in question.  
  17.    |  
  18.    | Default: true  
  19.   <interactiveMode>true</interactiveMode>  
  20.   -->  
  21.   
  22.   <!-- offline  
  23.    | Determines whether maven should attempt to connect to the network when executing a build.  
  24.    | This will have an effect on artifact downloads, artifact deployment, and others.  
  25.    |  
  26.    | Default: false  
  27.   <offline>false</offline>  
  28.   -->  
  29.   
  30.   <!-- pluginGroups  
  31.    | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.  
  32.    | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers  
  33.    | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.  
  34.    |-->  
  35.   <pluginGroups>  
  36.     <!-- pluginGroup  
  37.      | Specifies a further group identifier to use for plugin lookup.  
  38.     <pluginGroup>com.your.plugins</pluginGroup>  
  39.     -->  
  40.   
  41.     <pluginGroup>org.mortbay.jetty</pluginGroup>  
  42.   </pluginGroups>  
  43.   
  44.   
  45.   <!-- proxies  
  46.    | This is a list of proxies which can be used on this machine to connect to the network.  
  47.    | Unless otherwise specified (by system property or command-line switch), the first proxy  
  48.    | specification in this list marked as active will be used.  
  49.    |-->  
  50.   <proxies>  
  51.   </proxies>  
  52.   
  53.   <!-- servers  
  54.    | This is a list of authentication profiles, keyed by the server-id used within the system.  
  55.    | Authentication profiles can be used whenever maven must make a connection to a remote server.  
  56.    |-->  
  57.   <servers>  
  58.     <!-- server  
  59.      | Specifies the authentication information to use when connecting to a particular server, identified by  
  60.      | a unique name within the system (referred to by the 'id' attribute below).  
  61.      |   
  62.      | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are   
  63.      |       used together.  
  64.      |  
  65.     <server>  
  66.       <id>deploymentRepo</id>  
  67.       <username>repouser</username>  
  68.       <password>repopwd</password>  
  69.     </server>  
  70.     -->  
  71.       
  72.     <!-- Another sample, using keys to authenticate.  
  73.     <server>  
  74.       <id>siteServer</id>  
  75.       <privateKey>/path/to/private/key</privateKey>  
  76.       <passphrase>optional; leave empty if not used.</passphrase>  
  77.     </server>  
  78.     -->  
  79.     <server>  
  80.       <id>nexus</id>  
  81.       <username>admin</username>  
  82.       <password>xxxxxx</password>  
  83.     </server>  
  84.   </servers>  
  85.   
  86.   <!-- mirrors  
  87.    | This is a list of mirrors to be used in downloading artifacts from remote repositories.  
  88.    |   
  89.    | It works like this: a POM may declare a repository to use in resolving certain artifacts.  
  90.    | However, this repository may have problems with heavy traffic at times, so people have mirrored  
  91.    | it to several places.  
  92.    |  
  93.    | That repository definition will have a unique id, so we can create a mirror reference for that  
  94.    | repository, to be used as an alternate download site. The mirror site will be the preferred   
  95.    | server for that repository.  
  96.    |-->  
  97.   <mirrors>  
  98.     <!-- mirror  
  99.      | Specifies a repository mirror site to use instead of a given repository. The repository that  
  100.      | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used  
  101.      | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.  
  102.      |  
  103.       
  104.     <mirror>    
  105.       <id>central</id>  
  106.       <mirrorOf>*</mirrorOf>   
  107.       <name>Maven Central</name>    
  108.       <url>http://localhost:8081/nexus/content/repositories/central/</url>    
  109.     </mirror>      
  110.      -->  
  111.   </mirrors>  
  112.     
  113.   
  114.   <profiles>  
  115.    <profile>  
  116.       <id>dev</id>  
  117.   
  118.       <repositories>  
  119.         <repository>  
  120.           <id>nexus</id>  
  121.           <name>Nexus Repository</name>  
  122.           <url>http://localhost:8081/nexus/content/groups/public/</url>  
  123.      <releases>  
  124.            <enabled>true</enabled>  
  125.      </releases>  
  126.           <snapshots>  
  127.                 <enabled>false</enabled>  
  128.           </snapshots>  
  129.         </repository>  
  130.   
  131.         <repository>  
  132.           <id>thirdparty</id>  
  133.           <name>thirdparty</name>  
  134.           <url>http://localhost:8081/nexus/content/repositories/thirdparty/</url>  
  135.      <releases>  
  136.            <enabled>true</enabled>  
  137.      </releases>  
  138.           <snapshots>  
  139.                 <enabled>false</enabled>  
  140.           </snapshots>  
  141.         </repository>  
  142.       </repositories>  
  143.         
  144.       <pluginRepositories>  
  145.         <pluginRepository>  
  146.             <id>nexus</id>  
  147.             <url>http://localhost:8081/nexus/content/groups/public/</url>  
  148.             <releases>  
  149.               <enabled>true</enabled>  
  150.             </releases>  
  151.             <snapshots>  
  152.                 <enabled>false</enabled>  
  153.             </snapshots>  
  154.         </pluginRepository>  
  155.     </pluginRepositories>  
  156.       
  157.     </profile>  
  158.   </profiles>  
  159.   
  160.       
  161.   <activeProfiles>  
  162.     <activeProfile>dev</activeProfile>  
  163.   </activeProfiles>  
  164.     
  165.   <!-- activeProfiles  
  166.    | List of profiles that are active for all builds.  
  167.    |  
  168.   
  169.   <activeProfiles>  
  170.     <activeProfile>alwaysActiveProfile</activeProfile>  
  171.     <activeProfile>anotherAlwaysActiveProfile</activeProfile>  
  172.   </activeProfiles>  
  173.   -->  
  174. </settings>  
<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ~/.m2/repository
  <localRepository>C:/apache-maven-3.0.4/repository</localRepository>
  -->

  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->

	<pluginGroup>org.mortbay.jetty</pluginGroup>
  </pluginGroups>


  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
  </proxies>

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     | 
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are 
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->
    
    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
    <server>
      <id>nexus</id>
      <username>admin</username>
      <password>xxxxxx</password>
    </server>
  </servers>

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   | 
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred 
   | server for that repository.
   |-->
  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    
    <mirror>  
      <id>central</id>
      <mirrorOf>*</mirrorOf> 
      <name>Maven Central</name>  
      <url>http://localhost:8081/nexus/content/repositories/central/</url>  
    </mirror>    
     -->
  </mirrors>
  

  <profiles>
   <profile>
      <id>dev</id>

      <repositories>
        <repository>
          <id>nexus</id>
          <name>Nexus Repository</name>
          <url>http://localhost:8081/nexus/content/groups/public/</url>
	 <releases>
	       <enabled>true</enabled>
	 </releases>
          <snapshots>
                <enabled>false</enabled>
          </snapshots>
        </repository>

        <repository>
          <id>thirdparty</id>
          <name>thirdparty</name>
          <url>http://localhost:8081/nexus/content/repositories/thirdparty/</url>
	 <releases>
	       <enabled>true</enabled>
	 </releases>
          <snapshots>
                <enabled>false</enabled>
          </snapshots>
        </repository>
      </repositories>
      
      <pluginRepositories>
		<pluginRepository>
			<id>nexus</id>
			<url>http://localhost:8081/nexus/content/groups/public/</url>
			<releases>
			  <enabled>true</enabled>
		    </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
		</pluginRepository>
	</pluginRepositories>
	
    </profile>
  </profiles>

    
  <activeProfiles>
    <activeProfile>dev</activeProfile>
  </activeProfiles>
  
  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |

  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>


注意:<profile>中的<id>的值一定要为nexus,而且要与<server>的<id>的值相同个人认为此与Server配置下的Base URL:http://xxx.xx.xx.xxx:8081/nexus有关,另外我注释掉了<mirror>,主要在无法访问MAVEN中心库才启用。

 

 

===============

http://www.iteye.com/topic/306449

我对比了一些maven的私服以后,感觉nexus最好使,把搭建的过程步骤一下吧,我的环境是cent5, tomcat 6
1、下载war包,部署到tomcat中,启动tomcat;
2、访问:http://xxx/nexus-1.1.1/index.html;
3、用admin/admin123登录;
4、修改admin的密码,但是不要修改别的属性和修改别的用户信息
5、进入administration中的repositories,依次修改三个type是proxy的项目,将其Download Remote Indexes修改为true;然后邮件他们,分别re-index一下;
6、将你自己机器上的manven缓存(一般是在C:\Documents and Settings\登录名\.m2下面)全部拷贝到/home/你的用户名/sonatype-work/nexus/storage下面的central和releases各一份;
7、修改你本地的(一般是在C:\Documents and Settings\登录名\.m2下面)setting.xml文件改成下面的:

Xml代码 复制代码  收藏代码
  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>172.19.0.177:8080/nexus-1.1.1</host>  
  10.           <port>80</port>  
  11.           <nonProxyHosts>172.19.0.177:8080/nexus-1.1.1</nonProxyHosts>  
  12.         </proxy>  
  13.       </proxies>  
  14.       <servers>  
  15.       </servers>  
  16.       <mirrors>  
  17.          <mirror>  
  18.           <id>nexus-public-snapshots</id>  
  19.           <mirrorOf>public-snapshots</mirrorOf>  
  20.           <url>http://172.19.0.177:8080/nexus-1.1.1/content/groups/public-snapshots</url>  
  21.         </mirror>  
  22.         <mirror>  
  23.           <!--This sends everything else to /public -->  
  24.           <id>nexus</id>  
  25.           <mirrorOf>*</mirrorOf>  
  26.           <url>http://172.19.0.177:8080/nexus-1.1.1/content/groups/public</url>  
  27.         </mirror>  
  28.       </mirrors>  
  29.       <profiles>  
  30.         <profile>  
  31.           <id>development</id>  
  32.           <repositories>  
  33.             <repository>  
  34.               <id>central</id>  
  35.               <url>http://central</url>  
  36.               <releases><enabled>true</enabled></releases>  
  37.               <snapshots><enabled>true</enabled></snapshots>  
  38.             </repository>  
  39.           </repositories>  
  40.          <pluginRepositories>  
  41.             <pluginRepository>  
  42.               <id>central</id>  
  43.               <url>http://central</url>  
  44.               <releases><enabled>true</enabled></releases>  
  45.               <snapshots><enabled>true</enabled></snapshots>  
  46.             </pluginRepository>  
  47.           </pluginRepositories>  
  48.         </profile>  
  49.         <profile>  
  50.           <id>public-snapshots</id>  
  51.           <repositories>  
  52.             <repository>  
  53.               <id>public-snapshots</id>  
  54.               <url>http://public-snapshots</url>  
  55.               <releases><enabled>false</enabled></releases>  
  56.               <snapshots><enabled>true</enabled></snapshots>  
  57.             </repository>  
  58.           </repositories>  
  59.          <pluginRepositories>  
  60.             <pluginRepository>  
  61.               <id>public-snapshots</id>  
  62.               <url>http://public-snapshots</url>  
  63.               <releases><enabled>false</enabled></releases>  
  64.               <snapshots><enabled>true</enabled></snapshots>  
  65.             </pluginRepository>  
  66.           </pluginRepositories>  
  67.         </profile>  
  68.       </profiles>  
  69.         <activeProfiles>  
  70.         <activeProfile>development</activeProfile>  
  71.       </activeProfiles>  
  72. </settings>  

 

    将172.19.0.177地址修改为你自己的服务器地址
   
8、在你的项目中的pom.xml中增加一段:

Xml代码 复制代码  收藏代码
  1. <distributionManagement>  
  2.         <repository>  
  3.             <id>repo</id>  
  4.             <name>public</name>  
  5.             <url>http://172.19.0.177:8080/nexus-1.1.1/content/repositories/releases</url>  
  6.         </repository>  
  7.         <snapshotRepository>  
  8.             <id>Snapshots</id>  
  9.             <name>Snapshots</name>  
  10.             <url>http://172.19.0.177:8080/nexus-1.1.1/content/repositories/snapshots</url>  
  11.         </snapshotRepository>  
  12.     </distributionManagement>  

 


这样一来经过我的测试,如果你在没有局域网的环境中(也就是没办法访问你的私服),只要将pom里面的那段删除就可以了。

 

==================

<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 
 
<!--  <proxies>
    <proxy>
   <active>true</active>
      <protocol>http</protocol>
      <host>webproxy.wlb.nsroot.net</host>
      <port>8080</port>
      <nonProxyHosts>host1|*.nam.nsroot.net</nonProxyHosts>
    </proxy>
  </proxies>-->
 
  <localRepository>${user.home}/.m2/repository</localRepository>
<!--  <localRepository>maven</localRepository>-->

<mirrors>
 <mirror>
    <id>Nexus</id>
    <name>Nexus Public Mirror </name>
    <url>http://host1:8081/nexus/content/repositories/Hermesmvnrep</url>
    <mirrorOf>central</mirrorOf>
  </mirror>
</mirrors>

  <servers>
    <server>
      <username>xxx</username>
      <password>xxx</password>
      <id>artifactory</id>
    </server>
  </servers>
 
 
 
 
  <profiles>
 <profile>
  <activation>
   <activeByDefault>True</activeByDefault>
  </activation>
   <repositories>
        <repository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central-local</id>
          <name>libs-release</name>
          <url>http://host2:8081/artifactory/libs-release-local</url>
        </repository>
        <repository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>libs-release</name>
          <url>http://host2:8081/artifactory/libs-release</url>
        </repository>
        <repository>
          <snapshots />
          <id>snapshots</id>
          <name>libs-snapshot</name>
          <url>http://host2:8081/artifactory/libs-snapshot</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>plugins-release</name>
          <url>http://host2:8081/artifactory/plugins-release</url>
        </pluginRepository>
        <pluginRepository>
          <snapshots />
          <id>snapshots</id>
          <name>plugins-snapshot</name>
          <url>http://host2:8081/artifactory/plugins-snapshot</url>
        </pluginRepository>
      </pluginRepositories>
      <id>artifactory</id>
    </profile>

  </profiles>
</settings>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值