简体   繁体   English

Java 1.8版本的Maven安装问题

[英]Maven install issue with Java 1.8 version

I have written code which can compile on Java 1.8 (try block). 我写了可以在Java 1.8(try块)上编译的代码。 It is compiled and running for me when I run it directly. 当我直接运行它时,它将为我编译并运行。 While I am trying to build it using Maven in my local, I am facing an issue which is saying to use -source 7 or later. 当我尝试在本地使用Maven进行构建时,遇到了一个问题,即要使用-source 7或更高版本。 I tried all possible ways to use java 8 and all places I have specified 8 only but Maven is trying to compile using java 1.6 it seems. 我尝试了所有可能的方式来使用Java 8,并且所有地方都只指定了8,但Maven似乎尝试使用Java 1.6进行编译。

Can any one you please help me where can I correct it to pick my maven to use java 1.8. 可以请任何人帮助我,在哪里可以更正我的Maven以使用Java 1.8。

Thanks, Venkat 谢谢,Venkat

Following should work too: 以下也应该工作:

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

You can specify that using the maven-compiler-plugin : 您可以使用maven-compiler-plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.6.0<</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
 </plugin>

Just remember to use the newest version of the plugin. 只要记住要使用最新版本的插件即可。

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

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