maven+nexus

1.1

安装 nexus

1 )下载 http://nexus.sonatype.org/downloads/   nexus-2.2-01-bundle.zip

2) 执行nexus-2.1.2\bin\jsw\windows-x86-32中的install-nexus.bat安装服务

3)执行start-nexus.bat启动服务

4)打开浏览器,输入 http://localhost:8081/nexus ,看到成功界面

1.2 

nexus  端口配置在nexus/conf/nexus.properties 文件中

1.3

nexus 中库的类型:

hosted宿主仓库:本地仓库,创建hosted宿主仓库,只填 id和name就可以,Storage Location不要填,默认会是在work目录下;

proxy代理仓库,代理远程;创建proxy库,只填 id和name和远程库的url即可;

group,仓库组 可以代替所有已经选进去的库,Available Repositories 可用的库;

2.搭建Maven的Nexus私服,方解决开发团队无法上网的情况,当然就是都能上网,私服也能减少上网浪费的时间,减少中央库的压力:

如果你已经安装了nexus,可以在maven的settings.xml配置镜像,这样所有jar的下载机依赖分析都经过你的nexus

,nexus会缓存这些数据,以后其他人在获取不用再重新冲互联网下载了,也能解决其他人不能连入互联网的问题

<mirror> 
        <id>nexus</id> 
        <mirrorOf>*</mirrorOf> 
        <name>Nexus Mirror</name> 
        <url>http://192.168.1.5:81/nexus/content/groups/public/</url> 
</mirror>

3.重点:把本地下载的repository整个发布到nexus

用了私服后,

有事后出现有些jar依赖,无法用上面说的镜像的形式下载下来,

甚至配置了存在这些jar的 maven库的nexus 代理库,也取不到,

也有无法代理第三方的maven库的情况,原因未知:第三方库新版本的jar总是无法索引的我自己的nexus中

这种情况,我的处理办法是:

1)先去掉上面的镜像,用可以连入互联网的计算机,下载所有依赖,这样这些依赖就存到你的  本机 的maven缓存中了(一般是在C:\Documents and Settings\登录名\.m2\repository 下面)

2)然后在nexus  中创建 一个新的 Hosted Repository类型的库,或者干脆使用 nexus 带的thirdparty库,将呢 maven缓存全部copy到 nexus212\sonatype-work\nexus\storage\thirdparty中

3)这样就可以了,万一,如果这样还找不到,我碰上过一次原因是:

因为以前用镜像的形式,导致activiti-engine-5.10.jar找不到,结果maven在我的缓存中创建了一个activiti-engine-5.10.jar.lastUpdated文件和后来下载成功的activiti-engine-5.10.jar并存在同一个文件夹中

我将它们复制到nexus 带的thirdparty库中后,搜索到的 activiti-engine 结果找的的是 activiti-engine-5.10.jar.lastUpdated而不是 activiti-engine-5.10.jar 所有还是提示找不到

如果是这种情况,删除activiti-engine-5.10.jar.lastUpdated就行了,甚至删除maven缓存中所有 *.lastUpdated 。

4.

对于类型为release的proxy代理资源,资源中版本为snapshot的jar包将被阻塞掉,客户端无法获取,如果获取需要新建一个类型为snapshot的proxy代理,指向与前者相同的远程仓库地址

5.

validate: 验证项目是否正确以及相关信息是否可用
compile: 编译
test: 通过junit进行单元测试
package: 根据事先指定的格式(比如jar),进行打包
integration-test: 部署到运行环境中,准备进行集成测试
verify: 对包进行有效性性和质量检查
install: 安装到本地代码库
deploy: 在集成或发布环境,将包发布到远程代码库

1、archetype( 内建插件,他的create任务将建立项目骨架 ): archetype:create

2、groupId 项目的java包结构:com.aboy

3、artifactId 项目的名称:webmap

mvn clean  清理(删除target目录下编译内容)
mvn war:exploded  仅打包Web页面文件
    mvn eclipse:eclipse 
    mvn eclipse:clean 
生成清除Eclipse项目结构:

mvn help:effective-pom   显示Maven默认设置

6.pom文件 ,我原来的计算机上不出错,在一个新的机器上 遇到了一个 这样的异常
Multiple annotations found at this line:
    - Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-resources-plugin:2.4.3:resources
     (execution: default-resources, phase: process-resources)
    - Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-resources-plugin:2.4.3:testResources
     (execution: default-testResources, phase: process-test-resources)
    - Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile
     (execution: default-compile, phase: compile)
    - Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile
     (execution: default-testCompile, phase: test-compile)

后来发现 这个异常是 eclipse 的自带 maven的异常。eclipse 默认 3.6 和 3.7 已经添加 maven的 插件了 ,但有问题

使用 m2eclispe 替换 eclpse的maven。

猜你喜欢

转载自iliuyong.iteye.com/blog/1695034