Maven项目在编译及导入Eclipse时出现的错误处理汇总
Maven在构建项目时确实是比较强大,而且也越来越流行,目前不但越来越多的开源项目,甚至越来越多的商业项目都在使用Maven。但是不得不说Maven里面的坑真心的多,最近手头的几个项目都是使用Maven进行构建的,兄弟们都被Maven搞的泪奔啊....
一、Maven相关项目地址
Maven项目主页:
Maven下载地址:
http://maven.apache.org/download.cgi
Maven Eclipse Plugin
http://maven.apache.org/plugins/maven-eclipse-plugin/
Maven-android-plugin项目主页:
https://code.google.com/p/maven-android-plugin/
在
https://code.google.com/p/maven-android-plugin/wiki/Changelog可查看Maven-android-plugin的版本历史。
在线更新地址:
M2E Maven Archiver Connector
http://repo1.maven.org/maven2/.m2e/connectors/m2eclipse-mavenarchiver/0.15.0/N/0.15.0.201207090125/ Enabled
m2e-android
http://rgladwell.github.com/m2e-android/updates/ Enabled
二、编译错误汇总
1、关于编译Maven版本问题
(1) Maven3.0.5版本编译时,
Maven-android-plugin最高支持到3.5.3,更高版本的Maven-android-plugin,编译会出错。
(2) Maven3.1.1版本编译时,
Maven-android-plugin最好使用3.8.1
并且在Maven工程下的Android项目中,要指定SDK版本。否则提示SDK路径错误。添加如下:
<plugin> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>android-maven-plugin</artifactId> <version>3.8.1</version> <extensions>true</extensions> <configuration> <sdk> <platform>15</platform> </sdk> </configuration> </plugin>
若导入Eclipse环境,需要在CMD下执行mvneclipse:eclipse,然后使用导入已存在的Maven项目,该过程会重建Maven的Eclipse项目。
在Eclipse环境下执行Maven install时可能会报错,找不到tools.jar包。
那么要确认Eclipse中JREs的路径是否正确.
Condition:在使用Maven打包项目的时候出现这个异常,提示tools没有找到。
解决:确定你的eclipse在 首选项--》java--》installed JREs里面的jre指向的是JDK而不是JRE,tools.jar是JDK才有的。当然,你也可以在环境变量classpath里面将jdk的lib目录加加进去。
三、各类错误详细
3.1命令行编译打包问题
3.1.1 Maven3.0.5
1、配置Maven-android-plugin3.3.0~3.5.3
均可在CMD命令行模式下使用mvninstall 编译通过
2、配置Maven-Android-plugin3.6.0~3.8.1
配置Maven-Android-plugin3.6.0,提示的错误:
[ERROR] Failed to execute goalcom.jayway.maven.plugins.android.generation2:andr oid-maven-plugin:3.6.0:generate-sources(default-generate-sources) on project co ntroltower-android: Execution default-generate-sources ofgoal com.jayway.maven. plugins.android.generation2:android-maven-plugin:3.6.0:generate-sourcesfailed: No AndroidPlatform Version/API Level has been configured. Add e.g. <sdk><plat form>17</platform></sdk> to the pluginconfiguration. -> [Help 1] [ERROR]
配置Maven-Android-plugin3.7.0,提示的错误:
[ERROR] Failed to execute goalcom.jayway.maven.plugins.android.generation2:andr oid-maven-plugin:3.7.0:generate-sources(default-generate-sources) on project co ntroltower-android: Execution default-generate-sources ofgoal com.jayway.maven. plugins.android.generation2:android-maven-plugin:3.7.0:generate-sourcesfailed: No Android APILevel has been configured. Add e.g.<sdk><platform>17</platform ></sdk> to the plugin configuration. -> [Help1]
配置Maven-Android-plugin3.8.0,提示的错误:
[ERROR] Failed to execute goalcom.jayway.maven.plugins.android.generation2:andr oid-maven-plugin:3.8.0:generate-sources(default-generate-sources) on project co ntroltower-android: The plugincom.jayway.maven.plugins.android.generation2:andr oid-maven-plugin:3.8.0 requires Maven version 3.1.1 ->[Help 1] [ERROR]
错误处理:
对于Maven-android-plugin3.6.0~3.7.0版本,提示的是缺少配置Android SDK的配置项,可在Android项目的Maven配置文件pom.xml中添加AndroidSDK版本。
如下:
<pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <inherited>true</inherited> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>android-maven-plugin</artifactId> <version>3.7.0</version> <extensions>true</extensions> <configuration> <sdk> <platform>15</platform>//-->此处为Android SDK的版本号 </sdk> </configuration> </plugin> </plugins> </pluginManagement>
之后mvn install即可编译打包通过。
对于Maven-Android-plugin3.8.0其错误提示明确要求该插件需配置Maven3.1.1,故如果要使用Maven-Android-plugin3.8.0版本以上的插件则必须使用Maven3.1.1版本。
3.1.2 Maven3.1.1
在Android项目的maven配置文件中配置不同的Maven-android-plugin版本后,在CMD命令行环境中执行:mvn install,出现的各种错误如下:
配置Maven-Android-plugin3.3.0,提示的错误:
[ERROR] Failed to execute goalcom.jayway.maven.plugins.android.generation2:android-maven-plugin:3.3.0:generate-sources(default-generate-sources) on project controltower-android: Executiondefault-generate-sources of goalcom.jayway.maven.plugins.android.generation2:android-maven-plugin:3.3.0:generate-sourcesfailed: A required class wasmissing while executingcom.jayway.maven.plugins.android.generation2:android-maven-plugin:3.3.0:generate-sources:Lorg/sonatype/aether/RepositorySystem;
配置Maven-Android-plugin3.5.3,提示的错误:
[ERROR] Failed to execute goalcom.jayway.maven.plugins.android.generation2:android-maven-plugin:3.5.3:generate-sources(default-generate-sources) on project controltower-android: Executiondefault-generate-sources of goalcom.jayway.maven.plugins.android.generation2:android-maven-plugin:3.5.3:generate-sourcesfailed: A required classwas missing while executingcom.jayway.maven.plugins.android.generation2:android-maven-plugin:3.5.3:generate-sources:Lorg/sonatype/aether/RepositorySystem;
配置Maven-Android-plugin3.6.0,提示的错误:
[ERROR] Failed to execute goalcom.jayway.maven.plugins.android.generation2:android-maven-plugin:3.6.0:generate-sources(default-generate-sources) on project controltower-android: Executiondefault-generate-sources of goalcom.jayway.maven.plugins.android.generation2:android-maven-plugin:3.6.0:generate-sourcesfailed: A required classwas missing while executingcom.jayway.maven.plugins.android.generation2:android-maven-plugin:3.6.0:generate-sources:Lorg/sonatype/aether/RepositorySystem;
配置Maven-Android-plugin3.7.0,提示的错误:
[ERROR] Failed to execute goalcom.jayway.maven.plugins.android.generation2:android-maven-plugin:3.7.0:generate-sources(default-generate-sources) on project controltower-android: Executiondefault-generate-sources of goalcom.jayway.maven.plugins.android.generation2:android-maven-plugin:3.7.0:generate-sourcesfailed: A required classwas missing while executingcom.jayway.maven.plugins.android.generation2:android-maven-plugin:3.7.0:generate-sources:Lorg/sonatype/aether/RepositorySystem;
配置Maven-Android-plugin3.8.0,提示的错误:
[ERROR] Failed to execute goalcom.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.0:generate-sources(default-generate-sources) on project controltower-android: Executiondefault-generate-sources of goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.0:generate-sourcesfailed: No Android API Level has been configured. Add e.g.<sdk><platform>17</platform></sdk> to the pluginconfiguration. -> [Help 1]
配置Maven-Android-plugin3.8.1,提示的错误:
[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.1:generate-sources(default-generate-sources) on project controltower-android: Executiondefault-generate-sources of goalcom.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.1:generate-sourcesfailed: No Android API Level has been configured. Add e.g.<sdk><platform>17</platform></sdk> to the pluginconfiguration. -> [Help 1]
错误处理:
对于Maven3.1.1+Maven-androird-plugin3.3.0~3.7.0配置的错误提示:
A required classwas missing while executingcom.jayway.maven.plugins.android.generation2:android-maven-plugin:3.7.0:generate-sources:Lorg/sonatype/aether/RepositorySystem;
只能更新Maven-android-plugin插件至3.8.0+版本
对于Maven3.1.1+Maven-androird-plugin3.8.0+配置的错误提示:
[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.0:generate-sources(default-generate-sources) on project controltower-android: Executiondefault-generate-sources of goalcom.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.0:generate-sourcesfailed: No Android API Level has been configured. Add e.g.<sdk><platform>17</platform></sdk> to the pluginconfiguration. -> [Help 1]
需要在Andorid的Maven项目配置文件中添加Android SDK的版本配置项,如下:
<pluginManagement>
<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <inherited>true</inherited> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>android-maven-plugin</artifactId> <version>3.7.0</version> <extensions>true</extensions> <configuration> <sdk> <platform>15</platform>//-->此处为Android SDK的版本号 </sdk> </configuration> </plugin> </plugins> </pluginManagement>
综上所出现的错误,命令行编译打包Maven工程可使用的组合为:
Maven3.0.5+Maven-android-plugin3.3.0~3.5.3
maven3.1.1+Maven-android-plugin3.8.0~3.8.1
3.2 导入Eclipse时发生的错误提示
通过mvn eclipse:eclipse生成eclipse项目
在使用Eclipse导入maven项目时,提示错误:Resolve Later
Maven3.0.5+maven-android-plugin3.3.0提示:
Maven3.0.5+Maven-android-plugin3.5.3提示:
Maven3.0.5+Maven-android-plugin3.7.0提示:
使用Maven-android-plugin3.7.0在命令行编译通过后,Mvn eclipse:eclipse之后导入Eclipse环境中时提示错误:
No marketplaceentries found to handle android-maven-plugin:3.8.0:consume-aar in Eclipse. Please see Help for more information.
网络连接问题:
[ERROR] Failed to execute goal onproject javadrone-utils: Could not resolve dep endencies forproject com.codeminders:javadrone-utils:jar:1.3: Failed to collect dependencies atcom.twilight:h264-decoder:jar:1.0: Failed to read artifact desc riptor forcom.twilight:h264-decoder:jar:1.0: Could not transfer artifact com.tw ilight:h264-decoder:pom:1.0from/to central (http://repo.maven.apache.org/maven2): Connection to http://repo.maven.apache.orgrefused: Connection timed out: connect -> [Help 1]
四、关于错误Unsupported IClasspathEntrykind=4
在将Maven项目导入到Eclipse中时,出现错误完整提示如下:
Aninternal error occurred during: "Importing Maven projects".
Unsupported IClasspathEntry kind=4
这个错误网上有很多网友都提供了处理方法,这里就直接引用网友Kongqz对这个问题的处理办法:http://blog.csdn.net/kongqz/article/details/7770765,这个处理办法也是正确且是大多数网友采取的办法。如下:
这个异常会导致项目无法使用springide启动
英文解释如下:
Pleasesee https://bugs.eclipse.org/bugs/show_bug.cgi?id=374332#c14
Theproblem is caused by the fact that the STS (the Spring IDE/Eclipse) uses them2e(clipse) plugin but that eclipse:eclipse has been probably been run on theproject. When m2e encounters a "var" .classpath entry, it throws thiserror.
Inorder to fix this problem, you need to do 2 things:
1. Make sure that the version of them2e(clipse) plugin that you're running is at least 1.1.0. The update site ishere:https://repository.sonatype.org/content/repositories/forge-sites/m2e/1.1.0/N/LATEST/
2. Disable the maven nature for theproject (via the right-click menu), run mvn eclipse:clean (while your projectis open inSTS/eclipse), and then re-enable the maven nature.
中文解释就是
问题是因为使用springide使用了m2eclipse插件,但是这个插件的使用前提是不允许命令mvn eclipse:eclipse在项目上执行过,如果执行过,就会抛出这个异常。
现阶段修复这个问题需要做两件事
1、保证m2e插件的版本高于 1.1.0,如果没有到站点升级 : https://repository.sonatype.org/content/repositories/forge-sites/m2e/1.1.0/N/LATEST/
2、去掉项目的maven特性,右键菜单就能去除,然后执行mvn eclipse:clean,并且重新激活maven 特性