Jaskey Jaskey - 7 months ago 12
Java Question

How to make Maven use JDK1.8 instead of JDK1.6

I am new to maven, and I find that though I change the facet of the jdk of the project to 1.8, every time I "update maven",it will get back to jdk 1.6.

Why is that?

I installed jdk 1.8 in my windows, and I am using eclipse.

I read Specify JDK for Maven to use and add the following but it does not work.

<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>

Answer

The version of the JDK that maven will use is set in the maven-compiler-plugin like so:

  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
      <source>1.8</source>   <!-- use java 8 -->
      <target>1.8</target>
    </configuration>
  </plugin>

See Setting the -source and -target of the Java Compiler for more information.

Comments