Sonatype Nexus的安装配置参见:CentOS系统中安装Nexus并导入已有的构件库。Nexus内置了Jetty容器,${NEXUS_HOME}/bin/jsw目录下包含了各个操作系统的启动脚本。当然,如果你不喜欢内置的Jetty容器,也可以下载Nexus的war包,部署在tomcat等容器中。
安装部署后,比较重要的是能够对其进行深入的管理和配置,本文将介绍一些关于Sonatype Nexus的高级配置技巧,方便您进行配置管理。
<server> <id>thirdparty</id> <username>deployment</username> <password>password</password> </server>
默认情况下,Nexus监听端口8081。可以通过以下方法更改这个端口。
Nexus默认支持jar、war、pom、ejb、ear、rar、par等类型的包,如果希望能添加一些其它类型的包,可以配置如下:
在${nexus-work}/conf/packaging2extension-mapping.properties配置文件中增加配置:
my-custom-packaging=myextension
如果该配置文件不存在则手动创建该文件。
1)强制更新索引
nexus索引经常会出现与远程仓库索引不一致的情况,导致某些包不能正常下载,可以强制更新仓库索引,保持索引同步:
2)定时更新索引
如果Nexus本地索引中包含组件,但是却不能下载,可能的原因如下:
Nexus提供了可以调试组件下载过程的方法,在组件的下载全路径后面增加参数“?describe”,示例如下:
http://localhost:8081/nexus/content/groups/public/foo/bar/1.0/bar-1.0.jar?describe
Nexus将会以json的形式返回调试的输出结果,结果主要包括:
示例返回结果如下:
{
"data":{
"requestUrl":"http://localhost:8081/nexus/content/groups/public/test/project/1.0/project-1.0.jar?describe",
"processingTimeMillis":471,
"request":{
"requestUrl":"http://localhost:8081/nexus/content
/groups/public/test/project/1.0/project-1.0.jar?describe",
"requestPath":"/test/project/1.0/project-1.0.jar",
"requestContext":[
"request.received.timestamp=1276286536595",
"request.address=0:0:0:0:0:0:0:1%0",
"request.remoteOnly=false",
"request.url=http://localhost:8081/nexus/content/groups/public/test/project/1.0/project-
1.0.jar?describe",
"request.localOnly=false",
"request.appRootUrl=http://localhost:8081/nexus"
]
},
"response":{
"responseType":"NOT_FOUND",
"processedRepositoriesList":[
"public",
"snapshots",
"thirdparty",
"central",
"java.net-m2",
"java.net-m1-m2",
"google",
"apache-snapshots",
"codehaus-snapshots"
],
"appliedMappings":[
"public repository applied [11b647d6117038d8=
[type=EXCLUSION, groupId=public, patterns=[.*/project/.*], mappedRepositories=[releases]]]"
]
}
}
}
注意查看其中的response节点,如上例中的"responseType":"NOT_FOUND"表示未找到组件,通过该方法可以详细排查组件不能下载的原因。
再提供一个pom类型的包“mojo-parent-30.pom”的调试示例
{
"data": {
"requestUrl": "http://192.168.120.202:8081/nexus/content/groups/public/org/codehaus/mojo/mojo-parent/30/mojo-parent-30.pom?describe",
"processingTimeMillis": 1322,
"request": {
"requestUrl": "http://192.168.120.202:8081/nexus/content/groups/public/org/codehaus/mojo/mojo-parent/30/mojo-parent-30.pom?describe",
"requestPath": "/org/codehaus/mojo/mojo-parent/30/mojo-parent-30.pom",
"requestContext": [
"request.remoteOnly=false",
"request.localOnly=true"
]
},
"response": {
"responseType": "FILE",
"responseActualClass": "org.sonatype.nexus.proxy.item.DefaultStorageFileItem",
"responsePath": "/groups/public/org/codehaus/mojo/mojo-parent/30/mojo-parent-30.pom",
"responseUid": "central:/org/codehaus/mojo/mojo-parent/30/mojo-parent-30.pom",
"originatingRepositoryId": "central",
"originatingRepositoryName": "Central",
"originatingRepositoryMainFacet": "org.sonatype.nexus.proxy.maven.MavenProxyRepository",
"processedRepositoriesList": [ ],
"properties": [
"created=1333560570000",
"modified=1333560570000",
"lastRequested=1375255131976",
"remoteChecked=1375255131556",
"remoteUrl=http://repo1.maven.org/maven2/org/codehaus/mojo/mojo-parent/30/mojo-parent-30.pom",
"storedLocally=1375255131556",
"isExpired=false",
"readable=true",
"writable=true",
"virtual=false"
],
"attributes": [
"digest.md5=61a1f7765d45a51a6a7bb03bf410588f",
"digest.sha1=be742febdaa3cc7a971dacdf8cdc7ebd94b5765b",
"remote.sha1=be742febdaa3cc7a971dacdf8cdc7ebd94b5765b",
"request.address=192.168.120.121",
"request.user=anonymous",
"storageItem-checkedRemotely=1375255131556",
"storageItem-created=1333560570000",
"storageItem-expired=false",
"storageItem-generation=2",
"storageItem-lastRequested=1375255131976",
"storageItem-length=26627",
"storageItem-modified=1333560570000",
"storageItem-path=/groups/public/org/codehaus/mojo/mojo-parent/30/mojo-parent-30.pom",
"storageItem-readable=true",
"storageItem-remoteUrl=http://repo1.maven.org/maven2/org/codehaus/mojo/mojo-parent/30/mojo-parent-30.pom",
"storageItem-repositoryId=central",
"storageItem-storedLocally=1375255131556",
"storageItem-writable=true"
]
}
}
}