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
Why Can Array Constants Only Be Used in Initializers
Java Date Cut Off Time Information
Can't Make Jackson and Lombok Work Together
How to Mock Java.Time.Localdate.Now()
How to Identify Contents of a Byte[] Is a Jpeg
How to Rotate Jpeg Images Based on the Orientation Metadata
Formatting a String to a Currency Format in Jasper Report
Java: String Concat VS Stringbuilder - Optimised, So What Should I Do
How to Update Maven Repository in Eclipse
Calling Static Method from Another Java Class
Service Layer and Controller: Who Takes Care of What
List All Files in the Folder and Also Sub Folders
How to Execute .SQL Script File Using Jdbc
Deserializing an Abstract Class in Gson
Calling a Java Method to Draw Graphics