How to tell compiler to use openjdk 11 via pom.xml

13,488

Solution 1

The problem is probably in the version of Java you're using to run Maven. See the discussion here:

Unable to compile simple Java 10 / Java 11 project with Maven

If you want to make Maven recognize a target release of 10 or 11, you have to first run Maven with Java 11. Check that the Java that Maven is using is correct by doing mvn --version.

Solution 2

Here is a bit more advanced example that allows you to compile Java 11 while your main java version is 8. Most of my projects are still java 8 so I find it usefull.

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <release>11</release>
                <fork>true</fork>
                <executable>C:\Program Files\Java\jdk-11.0.2\bin\javac</executable>
            </configuration>
        </plugin>
Share:
13,488

Related videos on Youtube

R K
Author by

R K

Updated on June 27, 2022

Comments

  • R K
    R K almost 2 years

    How to configure OpenJDK 11 in pom file.

    <properties>
      <maven.compiler.plugin.version>3.8.0</maven.compiler.plugin.version>
      <maven.compiler.target>11</maven.compiler.target>
      <maven.compiler.source>11</maven.compiler.source>
    </properties>
    
    • BackSlash
      BackSlash almost 5 years
      You can't configure OpenJDK 11, you can configure maven to use java11, whether it will use Oracle Java or OpenJDK depends on which of the two is installed in your system and configured in your ide (or path, if you are using CLI). maven.apache.org/plugins/maven-compiler-plugin/examples/…
  • alexlipa
    alexlipa over 4 years
    this setup doesn't work for me. I have the same (main java 8 with a single submodule in 11). The compiler plugin just fails with no error and if I try to re-run the command that the plugin fires it actually works
  • Julie Pixie
    Julie Pixie almost 4 years
    this was the only thing that worked for me, every other suggestion failed when as soon as i hit the reimport button on maven, the iml file would switch back. thanks so much