`

使用nexus做Maven的私服

 
阅读更多
参考:
配置自己的maven库——nexushttp://lanhuidong.iteye.com/blog/1767941
Maven仓库管理之Nexushttp://my.oschina.net/aiguozhe/blog/101537
使用Nexus创建私服http://www.cnblogs.com/helong/articles/2254446.html
搭建maven+nexus环境http://blog.csdn.net/yongting1982/article/details/8529624
Maven入门实战笔记07-私服http://ln-ydc.iteye.com/blog/1829667
用Nexus做Maven私服全攻略 http://my.oschina.net/shootercn/blog/12269
用nexus搭建maven私服http://www.iteye.com/topic/1126678
Maven 实战 阅读 摘要:http://huangtut.iteye.com/blog/829446
Maven(创建私有仓库和设置权限) :http://blog.sina.com.cn/s/blog_6fe280b701012zs3.html
maven 手动加载第三方jar、zip包 http://jordy.easymorse.com/?p=207

中央仓库:  http://repo1.maven.org/maven2/
中央仓库中国镜像:http://maven.net.cn/content/groups/public
Java.net :http://download.java.net/maven/2/
JBoss: http://repository.jboss.com/maven2/

仓库搜索工具
Sonatype Nexus : http://repository.sonatype.org/
Jarvana : http://www.jarvana.com/jarvana/
MVNbrowser: http://www.mvnbrowser.com
MVNrepository: http://mvnrepository.com/

问题:
1. resolution will not be reattempted until the update interval of nexus has elapsed or updates are   forced
http://robiplus.iteye.com/blog/1025072
A:去nexus里去先"Update Index"再"Expire Cache".
B:如果不行,则去删除.m2/repository下面所有已经下载的库,在关闭eclipse,重新打开,Project->clean...........引起这个问题的原因,可能是下载太多库,导致有些下载出现问题,所以到本地的repository删除出现这个错误的库信息,然后在eclipse->project->clean,让插件重新下载相应的库,应该就没问题了.
C:上面方法都不行的话,那么可以自己找到jar,放到本地仓库.
D:同时,备份没问题的本地repository,放到nexus下面去,再执行Expire Cache.这个步骤可以使用Nexus+Command+Line+Tools工具,下面有介绍.
2. Plugin execution not covered by lifecycle configuration
http://blog.csdn.net/lhooouuu/article/details/6933569
解决办法: 下载安装m2e-wtp插件, 可以在eclipse market中找到. 会解决大部分eclipse读取pom.xml的错误. 下面看看m2e-wtp插件的描述: 大概是加强eclipse中maven的支持, 依赖war/ejp/ear/rar.....
装好后,右键pom.xml, open with "Maven POM Editor", 看见错误,就右键Quick Fix来修复.
http://blog.sina.com.cn/s/blog_725eee7e01015axt.html
右键工程,选择“maven”-->‘Update Project Configuration...’
3. The container 'Maven Dependencies' references non existing library ......jar
找到这个jar应该存放的路径,删除里面的所有信息,然后把这个jar复制的.m2里面的这个位置,然后到eclipse做一次clean,就好。 引起这个的原因很多,有时候可能跟服务器的操作系统有关,CentOS做的服务器比较稳定,错误比较少。




Nexus 内置仓库介绍
Maven Gentral:该仓库代理Maven中央仓库,其策略为Release,因此只会下载和缓存中央仓库中的发布版本构件。
Release:这是一个策略为Release的宿主类型仓库,用来部署组织内部的发布版本构件。
Snapshots:这是一个策略为Snapshot的宿主类型仓库,用来部署组织内部的快照版本构件。
3rd party:这是一个策略为Release的宿主类型仓库,用来部署无法从公共仓库获得的第三方发布版本构件。
Apache Snapshots: 这是一个策略为Snapshot的代理仓库,用来代理Apache Maven仓库的快照版本构件。
Codehaus Snapshots: 这是一个策略为Snapshot的代理仓库,用来代理Codehaus Maven仓库的快照版本构件。
Google code: 这是一个策略为Release的代理仓库,用来代理Google Code Maven仓库发布版本构件。
java.net Maven2:这是一个策略为Release的代理仓库,用来代理java.net Maven仓库的发布版本构件
Public Repositories:该仓库组将上述所有策略为Release的仓库聚合并通过一致的地址提供服务
Public Snapshot Repositories: 该仓库组将上述所有的策略为Snapshot的仓库聚合并通过一致的地址提供服务。(在nexus-oss-webapp-1.9.2.3 这版本中没有此项)

Nexus的权限管理
Nexus的访问控制模块aNexus是基于权限做访问控制的,服务器的每一个资源都有相应的权限来控制,因此用户执行特定的操作时就必须有必要的权限。管理员必须以角色的方式将权限授予Nexus用户
Nexus预定义了三个用户
admin:该用户拥有对Nexus服务的完全控制,默认密码是admin123
deployment:该用户能够访问Nexus,浏览仓库内容,搜索,并且上传部署构件,但无法对Nexus进行任何配置,默认密码为deployment123
anonymous:该用户对应了所有未登录的匿名用户,它们可以浏览仓库并进行搜索

把本地下载的repository整个发布到nexus
http://blog.csdn.net/kandafool/article/details/6840076
这才是我真正要做到的。相关的内容是从nexus命令工具https://docs.sonatype.com/display/SPRTNXOSS/Nexus+Command+Line+Tools找到的。非常简单,就是把repository下的内容整个拷贝到sonatype-work\nexus\storage下的你目标仓库中。我hosted宿主仓库建了个local-centre,就放在下面。如果你是直接拷贝maven默认的repository,不要把cache文件夹也拷过去~ 然后去页面那右键点击Rebuild Metadata,重建元数据。包含它的组,也都去update index,更新索引。我的一拷贝过去,刷新下就有了,不过还是右键点击了下。这是你就可以在搜索那去验证,搜索一个只有本地库有的。
上面还提供一个分离仓库release和snapshot的工具,简单好用。
java -jar  nexus-repository-conversion-tool-1.7.2-cli.jar -r/home/juven/mixed_repo/ -o/home/juven/output_repos/
If everything is ok, you'll see output saying "Repository conversion is successful!" , and check the directory /home/juven/output_repos/, there are now 2 sub-directories mixed_repo_releases and mixed_repo_snapshots. So now the mixed repository is converted to 2 separated repositories.
Other Options
If you want the old mixed repository be removed automatically after the conversion, simply add a '-m' option. This means move the repo so the old one will be deleted. Notice that by default we keep the old mixed repository in place as a backup.
Import into Nexus
Now that you have the separated repository, importing the data into Nexus is easy.In the UI create the two hosted repositories you want to hold this data, one for snapshots and one for releases.
Then locate your sonatype-work folder on the Nexus server. By default it will be in ../sonatype-work (a sibling folder of the Nexus application) for the bundle, and in ~/sonatype-work if you used the war. Copy or Move the contents of the repositories into sonatype-work/storage/[NX:repository id] using the correct repository id's you just created. Don't forget to add these new repositories to a group and adjust any routing rules that you may have.
Then in the UI, navigate to the Browse Repository view, right click on each repository and run rebuild Maven Metadata and then Re-index. Once those tasks are complete, your import is done. (Once the Maven Metadata tasks are done, Maven will be able to access the files just fine...the Re-index is for searching or browsing via M2eclipse)

1. java -jar nexus-cli.jar -r/home/pandy/dev/.m2/repository/ -o/home/pandy/dev/nexus/repository ,这个命令就是导出repository的库.
(我自己的命令:java -jar nexus-cli.jar -r/home/pandy/dev/dev_cpm_libs/repository/ -o/home/pandy/dev/nexus/repository)
2. 到nexus建立一个local-centre的hosted仓库.
3. 进入到C:\Documents and Settings\Administrator\sonatype-work\nexus\storage\local-centre.
4. 把第1步得到的库复制到这里,只复制releases.
5. 点击local-centre右键, Repair Index, 然后看下面,点击Refresh,就看见刚加进去的包了.
6.  按照上面的方法,建立一个local-centre的hosted仓库,来保存snapshots类型.




1. 下载nexus-2.3.x.war包,并放到tomcat的webapp目录下.
2. 启动tomcat, 会自动部署nexus工程.
3. 输入:http://localhost:8080/nexus, 进入到nexus.在右上角输入admin/admin123登陆到系统.
4. 看左边菜单,选择Repositories, 右边现实所有的仓库配置.

初始化
默认安装后的访问路径为http://localhost:8081/nexus/, 管理员登录为admin/admin123,UI是用Ext搭建的,熟悉Ext的人根本没有操作障碍,登录后最重要的事情就是打开远程索引下载,操作为选 择菜单Administrator->Repositories,然后在右边打开的列表中依次选择type字段为proxy的记录,在下方的编辑区 中修改"Download Remote Indexes"值为true,
选择刚才Repository,右键点击, 选择"Repair Index".
**此步骤很重要. 默认安装的Nexus没有建立远程索引, 此命令强制重建远程索引
然后到左边Adminisortion -> Scheduled Tasks, 就在中间能看见,runing一个任务,可能很久,看网速.
等runing完成之后,再跑到Repositories,  看中下部的配置,选择Browse Index选项卡,点击Refresh,刷新完成以后,到左上角的Artifact Search, 输入:testing, 回车开始查找,就能看到很多包含testing的jar.表示更新Index成功.

上传第三方包,右边选择3rd party, 看下方的Artifact Upload.
Select GAV Definition Source
GAV Definition:GAV Parameters
Group:sqljdbc
Artifact:sqljdbc
Version:4.0
Packaging:jar

Select Artifact(s) to Upload
选择要上传的第三方包,sqljdbc4.jar, 然后点击Add Artifact按钮,把这个jar增加到列表.
Artifacts列表会显示刚才增加的jar.
最后点击下面的Upload Artifact(s)按钮,提示上传成功.

回到Browse Index选项卡,点Refresh刷新Index,则可以看到刚才上传的信息.

两种配置方式
A: 在pox.xml增加:表示使用nexus的仓库
	<repositories>
		<repository>
			<id>nexus</id>
			<url>http://192.168.0.196:8080/nexus/content/groups/public/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>
	<pluginRepositories>
		<pluginRepository>
			<id>nexus</id>
			<url>http://192.168.0.196:8080/nexus/content/groups/public</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</pluginRepository>
	</pluginRepositories>


B:在set.xml增加配置:
  
<!-- 配置服务器账户和密码 -->
  <servers>
	<server> 
	      <id>nexus</id> 
	      <username>admin</username>
	      <password>admin123</password>
	</server> 
  </servers>
<!-- 把所有镜像都通过nexus去查找,这个很重要,否则无法使用nexus的代理 -->
   <mirrors>
        <mirror>  
            <id>nexus</id>  
            <url>http://192.168.0.196:8080/nexus/content/groups/public</url>  
            <mirrorOf>*</mirrorOf>  
        </mirror> 
  </mirrors>   
<!-- 配置nexus -->
  <profiles>
	<profile>
		<repositories>
			<repository>
				<id>nexus</id>
				<url>http://192.168.0.196:8080/nexus/content/groups/public/</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>false</enabled>
				</snapshots>
			</repository>
		</repositories>
		<pluginRepositories>
			<pluginRepository>
				<id>nexus</id>
				<url>http://192.168.0.196:8080/nexus/content/groups/public</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>false</enabled>
				</snapshots>
			</pluginRepository>
		</pluginRepositories>
	</profile>
  </profiles> 
<!-- 配置被激活的配置 -->
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>


仓库使用:
A:maven镜像的包:
B:第三方包:在pox.xml的依赖下面增加:使用刚增加的sqljdbc4.jar包
	<dependency>
			<groupId>sqljdbc</groupId>
			<artifactId>sqljdbc</artifactId>
			<version>4.0</version>
		</dependency>

更新完成后,可以看见工程的classpath多出了:sqljdbc-4.0.jar包,表示使用第三方jar成功.

发布到仓库:
... ...
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics