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 时,eclipseMaven 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

刚开始以为是pomxmlfinalName 引起的。结果发现nexus 压根儿没有叫kunlun_management_release的仓库。

根本原因pom.xmlsnapshotRepository指定的仓库不存在

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

原因分析: 
mavenweb项目默认的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

 

1. 如何避免该问题

将课后资料中代码导入到你的Eclipse中,执行Maven Update推荐

回到家里无法连接教室的私服?

把私服地址注释掉默认会通过网络去apache的远程的中央仓库下载

开源中国的私服http://maven.oschina.net/help.html

 

2. JSP 头信息重复时将会报错

 

解决办法:删除重复的头信息

3. AngularJs错误

1)angular-1.6.4.js:14525 Possibly unhandled rejection

解决办法:

headers : {'Content-Type': 'application/x-www-form-urlencoded'}

 

4. MyBatis常见错误

1) mybatis项目启动时报“Result Maps collection already contains value forxxx”的解决方案

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath*:META-INF/spring/wms-*.xml]

Offending resource: class path resource [applicationContext.xml]; nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 19 in XML document from URL [jar:file:/C:/data/zengdq/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp3/wtpwebapps/wms-web-biz/WEB-INF/lib/wms-core.jar!/META-INF/spring/wms-core.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 19; columnNumber: 51; 元素 "mybatis:scan" 的前缀 "mybatis" 未绑定。

 

解决办法:

 

2) Invalid bound statement (not found)

 

 

解决办法:出现此问题时,先检查配置文件,配置文件用的是注解的形式,而系统使用的xml的形式。

 

 

 

3) org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 4; 与元素类型 "mapper" 相关联的 "namespace" 属性值不能包含 '<' 字符。

 

 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'deptMapper' defined in file [D:\Sofe\apache-tomcat-7.0.59\webapps\bawm_hr\WEB-INF\classes\com\bawei\hrm\mapper\DeptMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\Sofe\apache-tomcat-7.0.59\webapps\bawm_hr\WEB-INF\classes\mapper\EmployeeMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 4; 与元素类型 "mapper" 相关联的 "namespace" 属性值不能包含 '<' 字符。

 

解决办法:这种情况一般都是配置文件格式写错了,根据报的错误坐标去找对应的错误

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值