Search code examples
javaeclipsemavenm2eclipsem2e

How to set default JDK for new Maven projects in Eclipse?


When I create new Maven project in Eclipse wizard, it uses J2SE-1.5. I would like to set it up to use default execution environment, which is JavaSE-1.8.

I know I can set it in pom or change in project preferences, but I would like to change the default JRE, not doing that for each new project.

When I create a new Java project (not Maven), it works as expected.

I have proper JDK added under "Installed JREs" and it's even only matched with the latest SE, not the Maven-1.5.

I'm using Eclipse Oxygen, Maven 3.5.0 and m2e 1.8.


Solution

  • In your project POM add

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

    This will apply to maven build cycle, and eclipse m2e integration plugin will pickup those as well. Just remember to maven refresh project after changing such settings in order for eclipse to apply (usually alt+f5 - Refresh Maven project.

    If you have parent-child modular structure, you cant put properties into parent POM. It is also possible to "globally" add properties to all projects on given machine using settings.xml file like described here Injecting POM Properties via Settings.xml