1. 程式人生 > >Maven專案在編譯及匯入Eclipse時出現的錯誤彙總處理

Maven專案在編譯及匯入Eclipse時出現的錯誤彙總處理

Maven專案在編譯及匯入Eclipse時出現的錯誤處理彙總

Maven在構建專案時確實是比較強大,而且也越來越流行,目前不但越來越多的開源專案,甚至越來越多的商業專案都在使用Maven。但是不得不說Maven裡面的坑真心的多,最近手頭的幾個專案都是使用Maven進行構建的,兄弟們都被Maven搞的淚奔啊大哭....

一、Maven相關專案地址

Maven專案主頁:

Maven下載地址:

Maven Eclipse Plugin

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

這個異常會導致專案無法使用springide啟動

英文解釋如下:

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:

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在專案上執行過,如果執行過,就會丟擲這個異常。

現階段修復這個問題需要做兩件事

 2、去掉專案的maven特性,右鍵選單就能去除,然後執行mvn eclipse:clean,並且重新啟用maven 特性