Maven入门实战笔记07-私服

来源:互联网 发布:工业ccd控制软件 编辑:程序博客网 时间:2024/05/14 06:43

使用Nexus创建私服

私服:见 Maven入门实战笔记04-仓库 一节中相关内容

 

三种Maven仓库管理软件:

Apache的Archiva

JFrog的Artifactory

Sonatype的Nexus

 

安装Nexus

下载Nexus

http://www.sonatype.org/nexus

Bundle:http://www.sonatype.org/downloads/nexus-latest-bundle.zip

WAR:http://www.sonatype.org/downloads/nexus-latest.war

安装

Bundle方式安装

自带Jetty容器

将下载的压缩包解压到 D:\tools\nexus-2.3.1-01-bundle

nexus-2.3.1-01包:包含Nexus运行所需文件

sonatype-work包:包含Nexus生成的配置文件、日志文件、仓库文件

备份Nexus,默认备份第2个文件

启动:命令行到该目录下 D:\tools\nexus-2.3.1-01-bundle\nexus-2.3.1-01\bin\

运行

Java代码  收藏代码
  1. nexus install  

 

Java代码  收藏代码
  1. nexus start  

 

问题:(1)启动问题

Java代码  收藏代码
  1. wrapper  | OpenSCManager failed - 拒绝访问。 (0x5)  

 解决:以管理员身份运行命令行,再执行即可

(2)安装问题

Java代码  收藏代码
  1. wrapper  | The nexus-webapp service is not installed - 指定的服务未安装。 (0x424)  

解决:未安装,先安装,再运行即可

(3)启动问题

Java代码  收藏代码
  1. wrapper  | Starting the nexus service...  
  2. wrapper  | The nexus service was launched, but failed to start.  

 到D:\tools\nexus-2.3.1-01-bundle\nexus-2.3.1-01\bin\jsw\conf目录,找到wrapper.conf文件将

Java代码  收藏代码
  1. wrapper.java.command=java  

修改如下

Java代码  收藏代码
  1. wrapper.java.command=D:\tools\java\jdk1.7.0\bin\java  

不明白:我明明配了java环境,但是只写java就是启动不起来

 

War方式安装

 下载war包,该war包支持主流的Web容器,如Tomcat,Glassfish,Jetty和Resin

 

安装完成后访问:http://localhost:8081/nexus/index.html#welcome,默认端口是8081

登录Nexus

默认管理员用户名和密码admin/admin123

 

Nexus的仓库与仓库组

Nexus包含了各种类型的仓库概念,包括代理仓库、宿主仓库和仓库组

Nexus的内置仓库



 点击左侧Repositories,界面右边出现仓库列表

仓库有四种类型:group(仓库组)、hosted(宿主)、proxy(代理)和virtual(虚拟)

仓库的格式:Maven1或Maven2

仓库的策略(Policy):表示该仓库是发布(Release)版本仓库还是快照(Snapshot)版本仓库

最后两列为仓库的状态和路径

各个仓库用途:

1.Maven1格式和虚拟类型仓库不提,虚拟类型仓库作用实际上是动态地将仓库内容格式转换,也是为了服务Maven1格式

 

Nexus仓库分类的概念:

根据下图理解宿主仓库

仓库Nexus宿主仓库

add->Hosted Repository



 
 Repository ID:仓库ID、Repository Name:仓库名称、Repository Type:仓库类型

Provider:仓库格式、Repository Polioy:发布版还是快照版

Default Local Storage Location:表示该仓库的默认存储目录,待仓库创建好之后,该值就会成为基于sonatype-work的一个文件

Override Local Storage Location:可以用来 配置自定义仓库目录位置

创建Nexus代理仓库

 

多了Remote Storage Location:代表远程仓库的地址,必须输入有效值

Download Remote Indexes 表示是否下载远程仓库的索引

创建Nexus仓库组
在配置界面中,用户可以非常直观地选择Nexus中的仓库,将其聚合成一个虚拟的仓库组

Nexus的索引与构件搜索

为了能够搜索Maven中央库,首先设置Nexus中的Maven Central代理仓库下载远程索引

默认情况这个配置是关闭的

设置:选择中央-->Configuration-->设置Download Remote Indexes为true-->保存

查看状态:左侧Scheduled Tasks

GAV搜索:通过GroupId、ArtifactId和Version信息搜索

类名搜索:搜索包含某个Java类的构件

校验和搜索:直接使用构件的校验和来搜索该构件

以上搜索基于Nexus索引而实现,称为nexus-indexer

为宿主仓库和代理仓库建立索引,在仓库上右击,选择Update Index

配置Maven从Nexus下载构件

在Pom中为Maven配置仓库和插件仓库,只对当前Maven项目有效

通过一次配置让本机所有Maven项目都使用自己的Maven私服,配置settings.xml

但settings.xml并不支持直接配置repositories和pluginRepositories。Maven提供了Profile机制,能让用户将仓库配置放到setting.xml中的Profile中,如:

 

Java代码  收藏代码
  1. <settings>  
  2.     <profiles>  
  3.         <profile>  
  4.             <id>nexus</id>  
  5.             <repositories>  
  6.                 <repository>  
  7.                     <id>nexus</id>  
  8.                     <name>Nexus</name>  
  9.                     <url>http://localhost:8081/nexus/content/groups/public/</url>  
  10.                     <releases>  
  11.                         <enabled>true</enabled>  
  12.                     </releases>  
  13.                     <snapshots>  
  14.                         <enabled>true</enabled>  
  15.                     </snapshots>  
  16.                 </repository>  
  17.             </repositories>  
  18.             <pluginRepositories>  
  19.                 <pluginRepository>  
  20.                     <id>nexus</id>  
  21.                     <name>Nexus</name>  
  22.                     <url>http://localhost:8081/nexus/content/groups/public</url>  
  23.                 </pluginRepository>  
  24.             </pluginRepositories>  
  25.         </profile>  
  26.     </profiles>  
  27.     <activeProfiles>  
  28.         <activeProfile>nexus</activeProfile>  
  29.     </activeProfiles>  
  30. </settings>  
 该配置中使用了一个叫id为nexus的profile

 

activeProfile元素将nexus这个profile激活,这样当执行Maven构建时,激活的profile会将仓库配置应用到项目中去

配置镜像,让Maven只使用私服

 

Java代码  收藏代码
  1.     <!-- 配置镜像,让Maven只使用私服 -->  
  2.     <mirrors>  
  3.         <mirror>  
  4.             <id>nexus</id>  
  5.             <url>http://localhost:8081/nexus/content/groups/public</url>  
  6.             <mirrorOf>*</mirrorOf>  
  7.         </mirror>  
  8.     </mirrors>  
  9.       
  10.     <profiles>  
  11.         <profile>  
  12.             <id>nexus</id>  
  13.             <repositories>  
  14.                 <repository>  
  15.                     <id>nexus</id>  
  16.                     <url>http://central</url>  
  17.                     <releases>  
  18.                         <enabled>true</enabled>  
  19.                     </releases>  
  20.                     <snapshots>  
  21.                         <enabled>true</enabled>  
  22.                     </snapshots>  
  23.                 </repository>  
  24.             </repositories>  
  25.             <pluginRepositories>  
  26.                 <pluginRepository>  
  27.                     <id>nexus</id>  
  28.                     <url>http://central</url>  
  29.                 </pluginRepository>  
  30.             </pluginRepositories>  
  31.         </profile>  
  32.     </profiles>  
  33.     <activeProfiles>  
  34.         <activeProfile>nexus</activeProfile>  
  35.     </activeProfiles>  
  36. </settings>  
 
仓库与插件仓库配置,它们的id都是central,覆盖了超级POM中央仓库的配置

 

部署构件至Nexus

代理仓库:代理外部公共仓库

宿主仓库:存储组织内部的,或者一些无法从公共仓库中获得的第三方构件

使用Maven部署构件至Nexus每个项目POM的配置

Java代码  收藏代码
  1. <settings>  
  2.     <!-- 配置Maven部署构件至Nexus -->  
  3.     <distributionManagement>  
  4.         <repository>  
  5.             <id>nexus-releases</id>  
  6.             <name>Nexus Releases Repository</name>  
  7.             <url>http://localhsot:8081/nexus/content/repositories/releases</url>  
  8.         </repository>  
  9.         <snapshotRepository>  
  10.             <id>nexus-snapshots</id>  
  11.             <name>Nexus Snapshots Repository</name>  
  12.             <url>http://localhsot:8081/nexus/content/repositories/snapshots</url>  
  13.         </snapshotRepository>  
  14.     </distributionManagement>  
  15. </project>  
 为部署构件至Nexus配置认证信息,settings.xml的配置
Java代码  收藏代码
  1. <settings>  
  2.     <!--  为部署构件至Nexus配置认证信息 -->  
  3.     <servers>  
  4.         <server>  
  5.             <id>nexus-releases</id>  
  6.             <username>admin</username>  
  7.             <password>admin123</password>  
  8.         </server>  
  9.         <server>  
  10.             <id>nexus-snapshots</id>  
  11.             <username>admin</username>  
  12.             <password>admin123</password>  
  13.         </server>  
  14.     </servers>  
  15. </settings>  
 

 

手动部署第三方构件至Nexus上传第三方构件,选择一个宿主仓库如drd party-->在页面正文选择Artifact Upload选项卡

自定义坐标

Nexus的权限管理

Nexus的访问控制模块aNexus是基于权限做访问控制的,服务器的每一个资源都有相应的权限来控制,因此用户执行特定的操作时就必须有必要的权限。管理员必须以角色的方式将权限授予Nexus用户

Nexus预定义了三个用户

admin:该用户拥有对Nexus服务的完全控制,默认密码是admin123

deployment:该用户能够访问Nexus,浏览仓库内容,搜索,并且上传部署构件,但无法对Nexus进行任何配置,默认密码为deployment123

anonymous:该用户对应了所有未登录的匿名用户,它们可以浏览仓库并进行搜索

为项目分配独立的仓库-

Nexus的调度任务

Nexus提供了一系列可配置的调度任务来方便用户管理系统,用户可以设定这些任务的运行方式,例如每天、每周、手动。调度任务会在适当的时候在后台运行

左侧导航栏Scheduled Tasks-->Add

原链接http://ln-ydc.iteye.com/blog/1829667

0 0
原创粉丝点击