Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 906
JaskeyLam Avatar asked Oct 11 '14 18:10

JaskeyLam


People also ask

Does Maven work with Java 8?

2.1. The Maven compiler accepts this command with –target and –source versions. If we want to use the Java 8 language features, the –source should be set to 1.8. Also, for the compiled classes to be compatible with JVM 1.8, the –target value should be 1.8. The default value for both of them is the 1.6 version.

Does Maven support Java 6?

Jenkins >= 1.520 (1.531. 1 for LTS) requires Java 6 thus Maven jobs must be launched with a JDK >= 6. Jenkins >= 1.612 (1.625.

Which JDK does Maven use?

The Maven tool uses JDK version 11.0. 10. The default JDK is set to 13.0.

Is Java 1.8 the same as Java 8?

javac -source 1.8 (is an alias for javac -source 8 ) java.


1 Answers

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.

like image 176
azurefrog Avatar answered Sep 23 '22 02:09

azurefrog