Eclipse JRE System Library [J2SE-1.5]

40,516

Solution 1

The problem is not with Eclipse, but with the projects you're importing. m2e will set the project's JRE to match the maven project. The POM specifies the JRE version, and this is defaulted to 1.5 if not present. You need this in the POM:

<build>
     <plugins>
        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                   <source>1.7</source>
                   <target>1.7</target>
                </configuration>
        </plugin>
    </plugins>
</build>

Solution 2

artbristol gave the correct answer (and I upvoted him).

That was in 2012. Here is an update more appropriate for today (2016, Java 8, Spring 4.x/Servlet 3.x):

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

Solution 3

The root cause of this issue is Eclipse cannot resolve a valid value for the maven.compiler.source property when updating the .classpath file from the pom, it is simply using default one i.e

org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5.

Just Add following properties into you pom.xml and update project:

<properties>
            <javaVersion>1.8</javaVersion>
            <maven.compiler.source>${java.version}</maven.compiler.source>
            <maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
Share:
40,516

Related videos on Youtube

Sinisha Mihajlovski
Author by

Sinisha Mihajlovski

I'm a full stack software engineer that enjoys designing, engineering, fixing and automating stuff in the most simple and elegant way possible. I enjoy optimizing processes and cutting down the time from commit to production by implementing techniques like test driven development and continuous delivery increasing the effectiveness of the development teams.

Updated on July 09, 2022

Comments

  • Sinisha Mihajlovski
    Sinisha Mihajlovski almost 2 years

    I'm using Eclipse EE 3.7 with m2e plugin installed. I have JDK7 set in eclipse. When I import maven projects, the JRE is set to JRE System Library [J2SE-1.5], So i have compilation issues with java 6 related stuff. Instead I want the JRE in eclipse to be by default set to JRE System Library [J2SE-1.6]

    When i try to open a new project in eclipse File -> new -> Java project on the first screen i have an option to choose JRE and the third option is Use default JRE (currently 'jdk1.7.0_03')

    From this i can see that the default JRE in Eclipse is 1.7, but when i import new Maven projects, the JRE is set to 1.5 by default.

    Any help, how can i do this?

    • mbmast
      mbmast over 8 years
      I am experiencing a similary problem. Whatever the JRE System Library is set to, performing a Project>Maven>Update Project... resets the JRE System Library to J2SE-1.5.
    • groovedigga
      groovedigga over 4 years
      Old question but still helpful in 2019 since it happens also in current SpringBoot 2 projects.
  • Saikat
    Saikat over 10 years
    Here is some more info from Maven site
  • Xtroce
    Xtroce over 10 years
    for people who have more than one project this question could also be of interest stackoverflow.com/questions/2531650/…
  • Jugal Panchal
    Jugal Panchal almost 9 years
    I put it in <build><plugins></plugins></build> of pom file. It works, thanks!
  • Islam Azab
    Islam Azab over 7 years
    I have something like <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEnc‌​oding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> but I don't know the difference between it and your solution.
  • groovedigga
    groovedigga over 4 years
    Great answer, thx. This is the better solution in my case: Problems are shown in Eclipse but a maven build in the console works fine. Then I only need a hint for m2e and not an additional plugin-definition.