2015-01-20 50 views
0

在我的Ubuntu14.04系統中這很奇怪。我安裝了Oracle JDK 1.7。然後使用mvn編譯該項目。但是,錯誤報告:由於Java版本造成的mvn編譯錯誤

Apache Maven 3.0.5 
Maven home: /usr/share/maven 
Java version: 1.7.0_40, vendor: Oracle Corporation 
Java home: /opt/pro/JDK/jdk1.7.0_40/jre 
Default locale: en_US, platform encoding: UTF-8 
OS name: "linux", version: "3.13.0-43-generic", arch: "amd64", family: "unix" 
[INFO] Error stacktraces are turned on. 
[DEBUG] Reading global settings from /usr/share/maven/conf/settings.xml 
[DEBUG] Reading user settings from /home/shijiex/.m2/settings.xml 
[DEBUG] Using local repository at /home/shijiex/.m2/repository 
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10 for /home/shij.... 
     ............ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 1.547s 
[INFO] Finished at: Tue Jan 20 15:26:28 AST 2015 
[INFO] Final Memory: 7M/155M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project org.bytecode.generation.sample: Compilation failure: Compilation failure: 
[ERROR] /other/projectbase/workspace/org.bytecode.generation.sample/src/main/java/org/methodhandle/templates/TYPES.java:[3,7] error: enums are not supported in -source 1.3 
[ERROR] 
[ERROR] (use -source 5 or higher to enable enums) 
[ERROR] /other/projectbase/workspace/org.bytecode.generation.sample/src/main/java/org/methodhandle/templates/Templates.java:[7,19] error: generics are not supported in -source 1.3 
[ERROR] 
[ERROR] (use -source 5 or higher to enable generics) 
[ERROR] /other/projectbase/workspace/org.bytecode.generation.sample/src/main/java/org/methodhandle/templates/BaseTemplate.java:[11,9] error: variable-arity methods are not supported in -source 1.3 
[ERROR] -> [Help 1] 
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project org.bytecode.generation.sample: Compilation failure 

此錯誤表明,JDK 1.7,但它仍然使用1.3這樣的功能,例如,varity參數,枚舉,無法識別。

我是否缺少一些配置?

我沒有設置JAVA_HOME環境變量。默認值是Oracle 1.7,maven輸出也顯示爲1.7。

[email protected]:/other/projectbase/workspace 

/org.bytecode.generation.sample$ java -version 
java version "1.7.0_40" 
Java(TM) SE Runtime Environment (build 1.7.0_40-b43) 
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode) 
+0

什麼是你的'JAVA_HOME'設置的詳細信息? – Ascalonian 2015-01-20 19:38:26

回答

0

你可以這樣正確添加的東西到你的POM:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <version>3.2</version> 
    <configuration> 
     <source>${jdk.version}</source> 
     <target>${jdk.version}</target> 
    </configuration> 
</plugin> 

你可以找到的官方Maven Compiler plugin頁面

+1

默認值是1.5,所以在更改jdkversion時問題得到解決1.7 – 2015-01-20 20:35:02