score:267

Accepted answer

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.

score:-4

i changed eclipse from kepler to neon and then updated my project by with maven -> update project.

score:-1

check in pom.xml under properties if there is any tag with this maven.enforcer.plugin.version. delete it and replace that with the below code

<javaversion>1.8</javaversion>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>

under properties tag.

and under build, replace the plugins with the below code:

 <build>
    <finalname>1000springsecurityeg</finalname>
    
        <plugins>
            <plugin>
                <groupid>org.apache.maven.plugins</groupid>
                <artifactid>maven-compiler-plugin</artifactid>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
        
  </build>

this solution resolved my issue.

score:0

i allow myself to update that subject with java 11.

i have installed openjdk11 on my computer, and i wanted to use it in an app.

i had trouble because eclipse would always change my jre to javase-1.5 when i updated my project with maven.

i had set everything as you said, but i was always directly selecting in my java build path "java-11-openjdk.x86_64" as one of my alternante jre. i fixed my problem by selecting in "execution environment" javase-10 (but you have to double click on it and then choose as a compatible jre your openjdk11 version) as shown on the picture. execution environment setup

the project will use java 11 thanks to that (picture) but you have to write 10 for the java-version in the pom.xml and also set java 10 on the project facets.

score:0

i've resolved the issue installing the eclipse update "java 12" from the market. it makes my eclipse pass from kepler to luna.

after that, i have been able to set 1.8 as standard jdk, fixing the "maven update" problem.

score:0

i experienced with jre 15.0.1 one must only specify the compiler plugin like

<plugin>
    <groupid>org.apache.maven.plugins</groupid>
    <artifactid>maven-compiler-plugin</artifactid>
    <version>3.8.1</version>
    <configuration>
        <source>15</source>
        <target>15</target>
    </configuration>
</plugin>

if i also provide the properties like

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

this will again reset to jre 1.5 on maven / update project !!!

score:1

i had this problem. in my case the <properties> tag & nested tags jorge campos mentions above were in the wrong place. if i put them between the <hostversion> and <dependencies> tags in the pom.xml file, then this behaviour stopped.

that can be picked up in eclipse if validation of these files is switched on.

score:1

i am using java 11. this is how the complete pom.xml file looks like after adding <properties> and <plugin>

<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
  xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelversion>4.0.0</modelversion>
  <groupid>com.akshay</groupid>
  <artifactid>1000springsecurityeg</artifactid>
  <packaging>war</packaging>
  <version>0.0.1-snapshot</version>
  <name>1000springsecurityeg maven webapp</name>
  <url>http://maven.apache.org</url>
    
  <dependencies>
    <dependency>
      <groupid>junit</groupid>
      <artifactid>junit</artifactid>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  
    <properties>
        <javaversion>11</javaversion>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
    </properties>
  
  <build>
    <finalname>1000springsecurityeg</finalname>
    
        <plugins>
            <plugin>
                <groupid>org.apache.maven.plugins</groupid>
                <artifactid>maven-compiler-plugin</artifactid>
                <version>3.8.1</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
        </plugins>
        
  </build>
</project>

the above code worked for me. hope it works for you as well.

score:1

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

i added these lines in my "pom.xml" file and it worked.

score:2

i encounter similar issue on one of my team mate machine. he was using old version of eclipse, i believe it he was using keppler. project after being updated change jre version to 1.5.

simple updating eclipse to latest version solve this problem.

score:2

in my case (old jboss developer studio), the issue was the jre environments did not include 1.8 (only 1.7). when i switched the maven-compiler-plugin version to 1.7 and did maven update project, it updated the eclipse jre system library to 1.7. enter image description here

so the solution is to either get a newer ide version that includes a built-in jre environment that is 1.8 or later, or try to install it manually (see https://stackoverflow.com/a/35204314)

score:5

add this lines to your pom.xml, then right click your jre system library -> properties -> set your correct execution environment to java 1.8 or version you want to set.

<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> 

score:13

the root-cause of this issue is that if for any reason eclipse's cannot resolve a valid value for the maven.compiler.source property when generating/updating the .classpath file from the pom, it will simply default to using org.eclipse.jdt.launching.jre_container/org.eclipse.jdt.internal.debug.ui.launcher.standardvmtype/j2se-1.5.

as expertly answered by @jorge-campos, there are multiple ways to set that property.

however, jorge's answer didn't appear to work for me. here were my settings:

<properties>
    <javaversion>1.8</javaversion>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <maven.compiler.target>${java.version}</maven.compiler.target>
</properties>

...

exactly. ${java.version} is never going to resolve to the (completely different) property javaversion and eclipse ignored the property and used the default.

which brings me back to the "for any reason" part i opened with; developer stupidity can be one of those reasons.

score:32

had the same issue when i installed java 9. my project would default to j2se-1.5 execution environment. strangely, java 9 compliance level is not referenced like previous versions, i.e. "1.8", but as "9". so i had to provide my properties and maven compiler plugin config accordingly:

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

and

<plugin>
    <groupid>org.apache.maven.plugins</groupid>
    <artifactid>maven-compiler-plugin</artifactid>
    <configuration>
        <source>9</source>
        <target>9</target>
    </configuration>
</plugin>

this seems to have solved the problem. works for versions 9 and above.


Related Query

More Query from same tag