What Causes Imported Maven Project in Eclipse to Use Java 1.5 Instead of Java 1.6 by Default and How to Ensure It Doesn'T

What causes imported Maven project in Eclipse to use Java 1.5 instead of Java 1.6 by default and how can I ensure it doesn't?

The m2eclipse plugin doesn't use Eclipse defaults, the m2eclipse plugin derives the settings from the POM. So if you want a Maven project to be configured to use Java 1.6 settings when imported under Eclipse, configure the maven-compiler-plugin appropriately, as I already suggested:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>

If your project is already imported, update the project configuration (right-click on the project then Maven V Update Project Configuration).

Java version automatically change to java 1.5 after maven update

Open your pom.xml file and add the following lines on it:

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

Where 1.8 is the Java version of your current JDK/JRE. Another way of doing this is adding a <build> with the maven-compile-plugin as:

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version> <!-- or whatever current version -->
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

If you are looking for a way to make it work with Java versions 9+ please take a look at @JDelorean's answer.

How to compile maven web project in different version and run in different version

Use the Maven compiler plugin to set the source and runtime version of jdk & jvm respectively.

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.6</source>
<target>1.8</target>
</configuration>
</plugin>
<plugins>
<pluginManagement>
<build>


Related Topics



Leave a reply



Submit