参考资料:
- 官方:http://maven.apache.org
- 权威maven参考:http://maven.apache.org/plugins/index.html
- Maven中文作者的《Maven权威指南》,我也做了个附件下载(版权属于原作者,这里只用来交流学习)
学习方法:
- 充分利用官方插件文档,可以到此搜索信息
我在这里找到了我所需要的东东。 - 例如: 在测试时需要maven库中的某个war,需要把war下载到test-classes文件夹,方便测试用例读取?
- 打开官方插件文档,搜索:copy,找到:dependency,dependency:copy和dependency:get都可以 使用dependency:copy,详细用法就都有了,使用例子:
-
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.3</version> <executions> <execution> <id>copy</id> <phase>test-compile</phase> <goals> <goal>copy</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>com.domain.group</groupId> <artifactId>mywar</artifactId> <version>0.0.1-SNAPSHOT</version> <type>war</type> <outputDirectory>${project.build.testOutputDirectory}</outputDirectory> </artifactItem> </artifactItems> <overWriteIfNewer>true</overWriteIfNewer> <stripVersion>true</stripVersion> </configuration> </execution> </executions> </plugin>
问题点滴:
- eclipse提示maven依赖包缺少文件:进入maven repo视图查看,很多包后面带有.lastupdate,这样的包都是假的,要不得,删除这些包后再次maven一切正常
- eclipse与maven插件结合时注意事项:
1. eclipse会自动build,按照标准java方式产生文件
2. maven会分别对待java和resources文件夹,所以java文件夹下的非java资源不会生成到classes文件夹中,而eclipse的自动build会自动生成- 问题现象:在eclipse中可以正常执行,mvn clean test时失败
- 因为mvn不会处理java文件中的任何资源到classes中。
- 所以资源文件不要放入java文件夹,只能放入resources文件夹
- maven用户配置文件放在:".m2/setting.xml"没有从maven安装目录复制一份过来即可
- maven: mvn deploy时用户和密码保存在.m2/setting.xml中,如:
<servers> <server> <id>nexus-releases</id> <username>admin</username> <password>admin</password> </server> <server> <id>nexus-snapshots</id> <username>admin</username> <password>admin</password> </server> </servers>
我们的maven工程:pom.xml怎样写<distributionManagement> <repository> <id>nexus-snapshots</id> <!-- <name>${project.name}</name> --> <url>http://localhost:8081/nexus/content/repositories/snapshots</url> </repository> </distributionManagement>
特别注意:
distributionManagement.repository.id必须和server(setting.xml)中配置的server.id一致,否则找不到用户名和密码 - web项目调试最佳实践:
- 问题,jar都让maven管理了,web-inf/lib下没有jar了,这个时候怎样调试web呢?
- 详见:[MAVEN]web工程的调试