如何使Maven使用JDK1.8而不是JDK1.6

Jas*_*key 7 java eclipse maven

我是maven的新手,我发现虽然我将项目的jdk的方面改为1.8,但每次我"更新maven"时,它都会回到jdk 1.6.

这是为什么?

我在我的窗口安装了jdk 1.8,我正在使用eclipse.

我阅读了指定JDK for Maven使用并添加以下内容但它不起作用.

   <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-enforcer-plugin</artifactId>
  <executions>
    <execution>
      <id>enforce-versions</id>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules>
          <requireJavaVersion>
            <version>1.8</version>
          </requireJavaVersion>
        </rules>
      </configuration>
    </execution>
  </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

azu*_*rog 7

maven将使用的JDK版本设置maven-compiler-plugin如下:

  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
      <source>1.8</source>   <!-- use java 8 -->
      <target>1.8</target>
    </configuration>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

有关Setting the -source and -target of the Java Compiler更多信息,请参阅