简体   繁体   English

我的Java 8源代码的Maven编译失败

[英]Maven compilation of my Java 8 source code fails

On my mac, I am trying to compile some Java 8 source code I wrote. 在我的Mac上,我正在尝试编译我编写的一些Java 8源代码。 It compiles fine in Eclipse, but in Maven, the compilation is failing. 它在Eclipse中编译良好,但是在Maven中,编译失败。

I get multiple errors of the form: 我收到以下形式的多个错误:

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/admin/eclipse/workspaces/default/Java8/src/main/java/language/utilities/MapDemo.java:[14,33] lambda expressions are not supported in -source 1.7
  (use -source 8 or higher to enable lambda expressions)

Running mvn -v yields: 运行mvn -v将产生:

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)
Maven home: /Users/admin/apache-maven-3.3.9
Java version: 1.8.0_91, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre
Default locale: en_IE, platform encoding: UTF-8
OS name: "mac os x", version: "10.12", arch: "x86_64", family: "mac"

Running the export command shows that the JAVA_HOME variable is set to: 运行export命令显示JAVA_HOME变量设置为:

JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home"

What is this '-source' property? 什么是“-源”属性? Why do I need to set it if my Java version is Java 8? 如果我的Java版本是Java 8,为什么需要设置它?

Set

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

in the properties of your pom . pom属性中

You should not set this in the settings.xml because you force other people to change their settings.xml and use JDK8 in all of their other projects by default! 您不应在settings.xml中进行settings.xml因为默认情况下您会强迫其他人更改其settings.xml并在其所有其他项目中使用JDK8!

You need to configure your plugin maven-compiler-plugin to set the source and target version that you want to use 您需要配置插件maven-compiler-plugin来设置要使用的版本和目标版本

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>

暂无
暂无

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

相关问题 Java上的Gild代码编译失败 - Code compilation fails on Gild in Java Eclipse Maven - 代码完成失败“此编译单元不在 Java 项目的构建路径上”和“无法下载索引”错误 - Eclipse Maven - Code Completion fails "This compilation unit is not on the build path of a Java project" and "Failed to Download Index" Error Maven编译失败,并显示-source 1.7中不支持静态接口方法的错误 - maven compilation fails with error static interface methods are not supported in -source 1.7 Maven编译时如何忽略Java源码目录? - How to ignore the Java Source directory during Maven Compilation? IntelliJ中的Java项目没有错误,但通过Maven编译失败 - Java project in IntelliJ is error free but compilation fails via Maven 通过Maven错误进行议程代码编译:AgendaSample1Impl.java:[47,81]错误:-source 1.5中不支持Diamond运算符 - Agenda code compilation via maven error: AgendaSample1Impl.java:[47,81] error: diamond operator is not supported in -source 1.5 如何在编译之前修改 Gradle 项目中的 Java 源代码而不修改磁盘上的文件? - How can I modify Java source code in my Gradle project prior to compilation without modifying the files on disk? 在Java中,源代码到字节代码的编译究竟在哪里? - Where exactly does the compilation of source code to byte code happen in Java? 为什么编译失败? [爪哇] - Why compilation fails? [Java] 相同的源代码,Eclipse构建成功但Maven(javac)失败 - Same source code, Eclipse build success but Maven (javac) fails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM