项目中使用了maven,而且搭建了nexus 私服。
经常会遇到如下问题:
(一)
众所周知,Maven在下载仓库中找不到相应资源时,会生成一个.lastUpdated为后缀的文件。如果这个文件存在,那么即使换一个有资源的仓库后,Maven依然不会去下载新资源。
解决方法:
(1)在执行mvn compile 之前把lastUpdated 文件删除;
(2)mvn compile -U
(3)
除了网上所说的在参数中加入-U以外,本文还提供另外一种方法,可以使大家不用删除.lastUpdated文件的情况下,让Maven去查找最新资源。
正常情况下,我们是把仓库地址配置在settings.xml文件中的mirror节点下,这时如果生成了.lastUpdated文件,默认Maven是不会去取最新资源,但是如果我们把仓库资源配置在settings.xml的<profile>节点中,而不是mirror节点,那么即使更新失败,下一次同步也会忽略这些文件(注意:本人对Maven研究还很浅薄,不清楚使用profile配置仓库和使用mirror到底有什么区别和影响,这里仅仅列出此方法,在没有把握的情况下不推荐大家使用)。
<profile>配置如下:
<profiles>
<profile>
<id>dev<id> <!-- 这个id要和activeProfile里的id一样 -->
<repositories>
<repository>
<id>Nexus</id>
<url>http://192.168.9.91:8084/nexus/content/groups/futuresoftware</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
(二)使用maven 编译(mvn compile)时,报错:maven source 1.3 中不支持泛型
解决方法:在项目的pom.xml中添加:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
(三)执行 mvn deploy时报错:java.lang.OutOfMemoryError: Java heap space
解决方法:
执行deploy时指定jre的参数
-Xms128M -Xmx512M
(四)使用nexus 时,eclipse中 Maven Repositories 视图中的Global Repositories下的nexus 无法展开
解决方法:
对nexus 中Public Repositories 先执行“Rebuild Metadata”,再执行“Update Index”:
(五)使用eclipse 执行deploy部署项目时报错,报错信息如下:
刚开始以为是pom。xml中finalName 引起的。结果发现nexus 压根儿没有叫“kunlun_management_release”的仓库。
根本原因:pom.xml中snapshotRepository指定的仓库不存在。