转载:http://blog.csdn.net/leo115/article/details/8187451
Maven工程打包时出现 [INFO] Compilation failure;
[ERROR] COMPILATION ERROR
问题解决办法
- [INFO] Scanning for projects...
- [INFO] ------------------------------------------------------------------------
- [INFO] Building brandCtr Maven Webapp
- [INFO] task-segment: [package]
- [INFO] ------------------------------------------------------------------------
- [INFO] [resources:resources]
- [WARNING] Using platform encoding (utf-8 actually) to copy filtered resources, i.e. build is platform dependent!
- [INFO] Copying 2 resources
- [WARNING] POM for 'org.springframework:spring-transaction:pom:3.0.5.RELEASE:compile' is invalid. It will be ignored for artifact resolution. Reason: Failed to validate POM for project org/springframework:spring-transaction at Artifact [org.springframework:spring-transaction:pom:3.0.5.RELEASE:compile]
- [WARNING] POM for 'org.springframework:spring-transaction:pom:3.0.5.RELEASE:compile' is invalid. It will be ignored for artifact resolution. Reason: Failed to validate POM for project org/springframework:spring-transaction at Artifact [org.springframework:spring-transaction:pom:3.0.5.RELEASE:compile]
- [INFO] [compiler:compile]
- [INFO] Compiling 9 source files to D:\eclipse-jee\workspace\brandCtr\target\classes
- [INFO] ------------------------------------------------------------------------
- [ERROR] BUILD FAILURE
- [INFO] ------------------------------------------------------------------------
- [INFO] Compilation failure
- D:\eclipse-jee\workspace\brandCtr\src\main\java\dao\IQueryDAO.java:[12,5] -source 1.3 涓笉鏀寔娉涘瀷
- 锛堣浣跨敤 -source 5 鎴栨洿楂樼増鏈互鍚敤娉涘瀷锛?
- List<Adzone> getAdzoneListByTimeList(List<Integer> timeList);
- D:\eclipse-jee\workspace\brandCtr\src\main\java\util\TimeUtil.java:[36,19] -source 1.3 涓笉鏀寔娉涘瀷
- 锛堣浣跨敤 -source 5 鎴栨洿楂樼増鏈互鍚敤娉涘瀷锛?
- public static List<Integer> getResentTimeList(int days) {
- D:\eclipse-jee\workspace\brandCtr\src\main\java\web\QueryController.java:[29,1] -source 1.3 涓笉鏀寔娉ㄩ噴
- 锛堣浣跨敤 -source 5 鎴栨洿楂樼増鏈互鍚敤娉ㄩ噴锛?
- @Controller
- D:\eclipse-jee\workspace\brandCtr\src\main\java\web\QueryController.java:[65,6] -source 1.3 涓笉鏀寔娉涘瀷
- 锛堣浣跨敤 -source 5 鎴栨洿楂樼増鏈互鍚敤娉涘瀷锛?
- List<Integer> timeList = TimeUtil.getResentTimeList(days);
- D:\eclipse-jee\workspace\brandCtr\src\main\java\web\QueryController.java:[72,21] -source 1.3 涓笉鏀寔 for-each 寰幆
- 锛堣浣跨敤 -source 5 鎴栨洿楂樼増鏈互鍚敤 for-each 寰幆锛?
- for (Adzone adzone : adzoneList) {
- D:\eclipse-jee\workspace\brandCtr\src\main\java\dao\QueryDAOImpl.java:[19,2] -source 1.3 涓笉鏀寔娉ㄩ噴
- 锛堣浣跨敤 -source 5 鎴栨洿楂樼増鏈互鍚敤娉ㄩ噴锛?
- @Override
- D:\eclipse-jee\workspace\brandCtr\src\main\java\dao\QueryDAOImpl.java:[20,12] -source 1.3 涓笉鏀寔娉涘瀷
- 锛堣浣跨敤 -source 5 鎴栨洿楂樼増鏈互鍚敤娉涘瀷锛?
- public List<Adzone> getAdzoneListByTimeList(List<Integer> timeList){
- D:\eclipse-jee\workspace\brandCtr\src\main\java\dao\QueryDAOImpl.java:[23,19] -source 1.3 涓笉鏀寔 for-each 寰幆
- 锛堣浣跨敤 -source 5 鎴栨洿楂樼増鏈互鍚敤 for-each 寰幆锛?
- for(Adzone adzone:adzoneList){
- [INFO] ------------------------------------------------------------------------
- [INFO] For more information, run Maven with the -e switch
- [INFO] ------------------------------------------------------------------------
- [INFO] Total time: 1 second
- [INFO] Finished at: Thu Nov 15 16:23:12 CST 2012
- [INFO] Final Memory: 11M/20M
- [INFO] ------------------------------------------------------------------------
问题解析:
该错误是由于maven编译的时候使用了jdk1.3,而jdk1.3不支持泛型;
solution:
(1) 使用mvn -v 查看Maven版本
依赖的Java 版本是1.6.0_10-rc2
- Maven version: 2.0.10
- Java version: 1.6.0_10-rc2
- OS name: "windows xp" version: "5.1" arch: "x86" Family: "windows"
(2)maven2.0.10默认使用的是jdk1.3,而当前Maven要依赖 1.6版本,
解决办法:
可知原工程在 编译(compile)的阶段出现问题,检查 Maven 依赖的POM.XML文件中是否配置有 Maven编译的插件
如果没有可按如下配置编译插件
- <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>
- <finalName>brandCtr</finalName>
- </build>
配置好之后,重新在命令行中执行 mvn package 命令,第一遍可能还会出现错误,多执行几遍,便会打包成功,(一般执行第二遍时即可打包成功)。