maven系列三 —— nexus仓库安装配置(二)

一、nexus添加索引

1、配置nexus添加索引

 

2、从 http://pan.baidu.com/s/1gd69DKJ 下载nexus-maven-repository-index.zip

 

3、解压nexus-maven-repository-index.zip,将其复制到F:\a安装程序\maven\sonatype-work\nexus\indexer\central-ctx(根据自己的实际情况定),如图:

 

备注:要停止nexus服务之后才能添加

 

4、项目索引是为了使用者能够在私服站点查找依赖使用的功能

 

 

二、配置访问本地仓库

默认是在{user_home}/.m2目录,需修改配置{M2E_HOME}/conf/setting.xml文件,修改内容如下:

 <!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository>G:\c参考资料\maven\repository</localRepository>

 三、创建私服(nexus本地服务器)

1、nexus 更新私有仓库的索引(直接拷贝索引复制)

 

2、在setting.xml配置仓库,则本机中所有maven项目使用配置的私有仓库

<profiles>
	<profile>
		<id>huangbiao_repository</id>
		<repositories>
			<repository>
				<id>temp_hb</id>
				<name>temp_hb_name</name>
			<url>http://localhost:8081/nexus/content/groups/public/</url>
				<releases>
					<enabled>
						true
					</enabled>
				</releases>
				<snapshots>
					<enabled>
						true
					</enabled>
				</snapshots>
			</repository>
		</repositories>
	</profile>
</profiles>

<activeProfiles>
	<activeProfile>huangbiao_repository</activeProfile>
</activeProfiles>

3、设置镜像

在setting.xml文件中配置mirror镜像

<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>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
	<mirror>
		<id>central</id>
		<mirrorOf>*</mirrorOf>
<!--
	<mirrorOf>test_nexus</mirrorOf>
-->
		<name>Human Readable Name for this Mirror.</name>
		<url>http://localhost:8081/nexus/content/repositories/central/</url>
	</mirror>
</mirrors>

 按照例子中的示例,

1 先从本地仓库中查找是否存在该依赖,如果存在则不用寻找远程仓库

2 如果不存在依赖,并且没有配置镜像,则从远程仓库http://localhost:8081/nexus/content/groups/public/中下载数据(默认已经配置好了远程仓库地址)

3、如果不存在依赖,但是配置了镜像,则从镜像配置的网址服务器中先从远程仓库下载,然后用户再从配置的镜像服务器中下载

该私服服务器会将所有需要从远程服务器下载的内容先下载到http://localhost:8081/nexus/content/repositories/central/服务器上,用户再从http://localhost:8081/nexus/content/repositories/central/私服上下载。

 强调:很多在网上配置的是http://localhost:8081/nexus/content/groups/public/,但是本人经过测试发现无法从远程仓库下载依赖文件到本地仓库,但是使用这个http://localhost:8081/nexus/content/repositories/central/网址可以

四、项目发布

1、在pom.xml配置发布仓库的地址

<distributionManagement>
<repository>
	<id>maven_java</id>
	<name>maven_java_name</name>
	<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>

<snapshotRepository>
	<id>maven_java_snapshot</id>
	<name>maven_java_snapshot_name</name>
	<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>

2、在setting.xml配置文件中设置发布到nexus服务器的账号和密码

<servers>
	<server>
		<id>maven_java</id>
		<username>deployment</username>
		<password>deployment123</password>
	</server>
	<server>
		<id>maven_java_snapshot</id>
		<username>deployment</username>
		<password>deployment123</password>
	</server>
</servers>

 

猜你喜欢

转载自hbiao68.iteye.com/blog/2104519