一

概述


        Maven是一个项目管理和整合的工具。Maven为开发者提供了一套完整的构建生命周期框架。开发团队基本不用花多少时间就能自动完成工程的基础构建配置,因为Maven使用了一个标准的目录结构和一个默认的构建生命周期。在创建报告、检查、构建和测试自动配置时,Maven可以让开发者的工作变得更简单。但使用时总会碰到这个那个的异常,下面就总结一下常见的异常吧。maven常见异常处理_java

 二测试代码异常


[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-teston project web_nanchang: There are test failures.

[ERROR]

[ERROR] Please refer to E:\maven\web_nanchang\target\surefire-reports for the individual test results.

解决方法:

这是因为测试代码时遇到错误,它会停止编译。只需要在pom.xml的<project>里添加以下配置,使得测试出错不影响项目的编译。

<build>
   <plugins>
       <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-surefire-plugin</artifactId>
           <configuration>
               <testFailureIgnore>true</testFailureIgnore>
           </configuration>
       </plugin>
   </plugins>
</build>


 三构件下载异常


[ERROR] Failed to execute goal on project biz_zhuhai: Could not resolve dependencies for project 
biz_zhuhai:biz_zhuhai:jar:0.0.1-SNAPSHOTFailed to collect dependencies for [com.maywide.ibh:lib345:pom:1.0 (compile)]: Failed to read artifact descriptor for 
com.maywide.ibh:lib345:pom:1.0: Could not transfer artifact 
com.maywide.ibh:lib345:pom:1.0 from/to releases (http://localhost:9888/nexus-2.0.3/content/repositories/releases): Connection to 
http://localhost:9888 refused: Connection refused: connect -> [Help 1]

解决方法:

这是配置的url有错误或者是私服没有配好,导致构件下载时出错。如果没有jar包需要在私服里下载,可以不配置私服的,也就是可以把setting.xml的profiles里的东西全部删除的。

maven常见异常处理_java_02


 四

其他异常

1.异常一

[ERROR] Failed to execute goal org.codehaus.cargo:cargo-
maven2-plugin:1.0.6:start (start-containeron project myproject: Execution start-container of goal 
org.codehaus.cargo:cargo-maven2-plugin:1.0.6:start failedError while expanding 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\cargo\installs\apache-tomcat-6.0.29.zip
[ERROR] java.io.IOException: Negative seek offset

解决方法:

自己下载“apache-tomcat-6.0.29.zip”,将下载好的文件拷贝到指定文件夹“C:\Documents and Settings\Administrator\Local Settings\Temp\cargo\installs”下。

2.异常二

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war 
(default-war) on project web_nanchang: Error assembling WAR: 
webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]

解决方法:

maven的web项目默认的webroot是在src\main\webapp。如果在此目录下找不到web.xml就抛出以上的异常。解决方法在pom.xml加入以下的配置。红色字体改成你网站的根目录。

<build>
   <finalName>simple-webapp</finalName>
   <plugins>
       <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-war-plugin</artifactId>
           <version>2.1.1</version>
           <configuration>
               <webResources>
                   <resource>
                       <!-- this is relative to the pom.xml directory -->
                       <directory>WebContent</directory>
                   </resource>
               </webResources>
           </configuration>
       </plugin>
   </plugins>
</build>