Maven项目在编译及导入Eclipse时出现的错误汇总处理

转自 http://blog.csdn.net/netwalk/article/details/19071525

Maven在构建项目时确实是比较强大,而且也越来越流行,目前不但越来越多的开源项目,甚至越来越多的商业项目都在使用Maven。但是不得不说Maven里面的坑真心的多,最近手头的几个项目都是使用Maven进行构建的,兄弟们都被Maven搞的泪奔啊大哭....


一、Maven相关项目地址

Maven项目主页:

http://maven.apache.org/

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路径错误。添加如下:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1.   <plugin>  
  2.        <groupId>com.jayway.maven.plugins.android.generation2</groupId>  
  3.        <artifactId>android-maven-plugin</artifactId>     
  4.        <version>3.8.1</version>  
  5.        <extensions>true</extensions>  
  6.           <configuration>  
  7.          <sdk>  
  8.                <platform>15</platform>  
  9.          </sdk>  
  10.      </configuration>  
  11. </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,提示的错误:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. [ERROR] Failed to execute goalcom.jayway.maven.plugins.android.generation2:andr  
  2. oid-maven-plugin:3.6.0:generate-sources(default-generate-sources) on project co  
  3. ntroltower-android: Execution default-generate-sources ofgoal com.jayway.maven.  
  4. plugins.android.generation2:android-maven-plugin:3.6.0:generate-sourcesfailed:  
  5.  No AndroidPlatform Version/API Level has been configured. Add e.g. <sdk><plat  
  6. form>17</platform></sdk> to the pluginconfiguration. -> [Help 1]  
  7. [ERROR]  

配置Maven-Android-plugin3.7.0,提示的错误:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. [ERROR] Failed to execute goalcom.jayway.maven.plugins.android.generation2:andr  
  2. oid-maven-plugin:3.7.0:generate-sources(default-generate-sources) on project co  
  3. ntroltower-android: Execution default-generate-sources ofgoal com.jayway.maven.  
  4. plugins.android.generation2:android-maven-plugin:3.7.0:generate-sourcesfailed:  
  5.  No Android APILevel has been configured.  Add e.g.<sdk><platform>17</platform  
  6. ></sdk> to the plugin configuration. -> [Help1]  

配置Maven-Android-plugin3.8.0,提示的错误:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. [ERROR] Failed to execute goalcom.jayway.maven.plugins.android.generation2:andr  
  2. oid-maven-plugin:3.8.0:generate-sources(default-generate-sources) on project co  
  3. ntroltower-android: The plugincom.jayway.maven.plugins.android.generation2:andr  
  4. oid-maven-plugin:3.8.0 requires Maven version 3.1.1 ->[Help 1]  
  5. [ERROR]  

错误处理:

       对于Maven-android-plugin3.6.0~3.7.0版本,提示的是缺少配置Android SDK的配置项,可在Android项目的Maven配置文件pom.xml中添加AndroidSDK版本。

如下: 

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <pluginManagement>  
  2.     <plugins>  
  3.       <plugin>  
  4.         <groupId>org.apache.maven.plugins</groupId>  
  5.         <artifactId>maven-compiler-plugin</artifactId>  
  6.         <inherited>true</inherited>  
  7.         <configuration>  
  8.           <source>1.6</source>  
  9.           <target>1.6</target>  
  10.         </configuration>  
  11.       </plugin>  
  12.       <plugin>  
  13.         <groupId>com.jayway.maven.plugins.android.generation2</groupId>  
  14.         <artifactId>android-maven-plugin</artifactId>  
  15.         <version>3.7.0</version>  
  16.         <extensions>true</extensions>  
  17.                     <configuration>  
  18.                      <sdk>  
  19.                   <platform>15</platform>//-->此处为Android SDK的版本号  
  20.                      </sdk>  
  21.                  </configuration>  
  22.       </plugin>  
  23.     </plugins>  
  24.   </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,提示的错误:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. [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:  
  2. 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,提示的错误:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. [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:  
  2. 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,提示的错误:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. [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:  
  2. 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,提示的错误:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. [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:  
  2. 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,提示的错误:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. [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:  
  2.  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,提示的错误:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  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:  
  2.  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配置的错误提示:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. 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+配置的错误提示:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. [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:  
  2.  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>

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1.   <plugins>  
  2.      <plugin>  
  3.       <groupId>org.apache.maven.plugins</groupId>  
  4.       <artifactId>maven-compiler-plugin</artifactId>  
  5.       <inherited>true</inherited>  
  6.       <configuration>  
  7.         <source>1.6</source>  
  8.         <target>1.6</target>  
  9.        </configuration>  
  10.     </plugin>  
  11.     <plugin>  
  12.       <groupId>com.jayway.maven.plugins.android.generation2</groupId>  
  13.       <artifactId>android-maven-plugin</artifactId>  
  14.       <version>3.7.0</version>  
  15.       <extensions>true</extensions>  
  16.                   <configuration>  
  17.                    <sdk>  
  18.                 <platform>15</platform>//-->此处为Android SDK的版本号  
  19.                    </sdk>  
  20.                </configuration>  
  21.     </plugin>  
  22.   </plugins>  
  23. </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.

 

网络连接问题:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. [ERROR] Failed to execute goal onproject javadrone-utils: Could not resolve dep  
  2. endencies forproject com.codeminders:javadrone-utils:jar:1.3: Failed to collect  
  3.  dependencies atcom.twilight:h264-decoder:jar:1.0: Failed to read artifact desc  
  4. riptor forcom.twilight:h264-decoder:jar:1.0: Could not transfer artifact com.tw  
  5. 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]  
[html]  view plain  copy
  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 特性


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值