简体   繁体   English

Java版本导致的mvn编译错误

[英]mvn compilation error due to Java version

It is quite strange in my Ubuntu14.04 system. 在我的Ubuntu14.04系统中这很奇怪。 I installed Oracle JDK 1.7. 我安装了Oracle JDK 1.7。 And then compile the project using mvn. 然后使用mvn编译项目。 But error reports: 但是错误报告:

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

This errors shows that JDK is 1.7 but it is still use 1.3 so the features, eg, varity parameters, enum, are not recognized. 此错误表明JDK为1.7,但仍使用1.3,因此无法识别功能,例如变量参数,枚举。

Do i missing some configurations? 我会缺少一些配置吗?

I did not set JAVA_HOME environment variable. 我没有设置JAVA_HOME环境变量。 The default is Oracle 1.7 and the maven output also shows it is 1.7. 默认值为Oracle 1.7,maven输出也显示为1.7。

XXX@shijie-ThinkPad-T410:/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)

You can add something like this right into your POM: 您可以在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>

You can find more information on the official Maven Compiler plugin page 您可以在官方的Maven Compiler插件页面上找到更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM