1. Maven常见错误
项目中使用了maven,而且搭建了nexus 私服。
经常会遇到如下问题:
1) 使用maven 编译(mvn compile)时,报错:maven source 1.3 中不支持泛型
解决方法:在项目的pom.xml中添加:
Xml代码
1. <build>
2. <plugins>
3. <plugin>
4. <groupId>org.apache.maven.plugins</groupId>
5. <artifactId>maven-compiler-plugin</artifactId>
6. <configuration>
7. <source>1.7</source>
8. <target>1.7</target>
9. </configuration>
10. </plugin>
11. </plugins>
12. </build>
2) 执行 mvn deploy时报错:java.lang.OutOfMemoryError: Java heap space
解决方法:
执行deploy时指定jre的参数
-Xms128M -Xmx512M
3) 使用nexus 时,eclipse中 Maven Repositories 视图中的Global Repositories下的nexus 无法展开
解决方法:
对nexus 中Public Repositories 先执行“Rebuild Metadata”,再执行“Update Index”:
4) 使用eclipse 执行deploy部署项目时报错,报错信息如下:
Xml代码
1. Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project demoManagement: Failed to deploy artifacts: Could not find artifact com.kunlunsoft.jn:demoManagement:war:1.1.0-RELEASE in tdr_vks_management_release (http://192.168.2.150:8088/nexus/content/repositories/kunlun_management_release/) -> [Help 1]
项目名为demoManagement
刚开始以为是pom。xml中finalName 引起的。结果发现nexus 压根儿没有叫“kunlun_management_release”的仓库。
根本原因:pom.xml中snapshotRepository指定的仓库不存在。
5) webxml attribute is required
maven install web项目时报错:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project spring2: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
1
1
原因分析:
maven的web项目默认的webroot是在src\main\webapp。如果在此目录下找不到web.xml就抛出以上的异常。
解决办法:
将webroot修改为webapp
在pom.xml中指定web.xml,如下:
<build>
<finalName>web-app-name</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>${basedir}\WebContent\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
6) must be unique jar包重复
解决办法:
根据错误提示信息检查配置文件,把重复的jar删除
7) error in opening zip file
解决办法:
根据错误信息,删除mavan的本地仓库中对应的jar包,从新下载即可。
8) Updating Maven Project
9) Failed to clean project: Failed to delete
ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) on project hrm-manager: Failed to clean project: Failed to delete D:\work\20170529\hrm-manager\target\tomcat\logs\access_log.2017-07-09 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
解决办法:
启动任务管理器【ctrl】+【Alt】+【Delete】-> 进程 -> 并把javaw.exe的进程终止。
10) Maven项目中加载不到配置文件
DEBUG [localhost-startStop-1] - Ignoring bean class loading failure for bean 'dataSource'
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.mchange.v2.c3p0.ComboPooledDataSource] for bean with name 'dataSource' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource
解决方案:说明缺少c3p0.jar 查看pom文件
或是因为配置Spring.xml有问题,可参考(基于maven管理的项目中spring+mybatis配置数据源读取不到properties属性文件的问题)http://www.henryxi.com/read-values-from-properties-file-in-spring
去加载properties文件
11) 读取stax-api-1.0.1.jar时出错
出现.lastUpdated结尾的文件的原因:由于网络原因没有将Maven的依赖下载完整,导致。
解决方案:
1、 删除所有以.lastUpdate结尾的文件
a) 1、切换到maven的本地仓库
b) 2、在当前目录打开cmd命令行
c) 3、执行命令:for /r %i in (*.lastUpdated) do del %i
2、 在项目上执行 Maven Update (Alt + F5)
2. 如何避免该问题
l 将课后资料中代码导入到你的Eclipse中,执行Maven Update(推荐)
l 回到家里无法连接教室的私服?
n 把私服地址注释掉,默认会通过网络去apache的远程的中央仓库下载
l 开源中国的私服:http://maven.oschina.net/help.html