Why JRE Library is changed after Maven Update in Eclipse?

Viewed 724

I'm an Intellij user and now I need to use Eclipse to create a Maven web app. So I installed Eclipse, I added Tomcat and all. And I want to use Java 8 for my projects, but I have a problem because I try to change JRE System Library from 1.7 to 1.8, and when I do Maven -> Update Project it becomes 1.7. And I don't understand why.

So I create a Maven project and I choose the webapp archetype from org.apache.maven and at the beginning my project has JRE System Library 1.7

After that I try to choose it like this:

enter image description here

After that the JRE System Library becomes 1.8:

enter image description here

After that I do right click Maven -> Update project and the JRE System Library becomes 1.7:

enter image description here

Why the JRE Library is changed from 1.8 to 1.7 after Maven update? And what should I do to have JRE System Library 1.8?

This is my pom:

<?xml version="1.0" encoding="UTF-8"?>

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.abc</groupId>
  <artifactId>firstwebproj</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>firstwebproj Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <finalName>firstwebproj</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

Thanks in advance!

1 Answers

Look at your first picture. In the greyed out "Execution Environment" choice, the textfield has the content "JavaSE-1.7 (jdk1.8.0_201)". That JDK version is the same one you're trying to set it to use, but you have that JDK distro associated with Java SE 1.7.

In Eclipse Preferences, go to "Installed JREs", but go to the subfolder of that, "Execution Environments". In the left-hand list, you will see entries for "JavaSE-1.7" and hopefully "JavaSE-1.8". When you click each one of those, the right-hand list will populate with any available JDK/JRE installations.

You need to make sure that when you select "JavaSE-1.7", that NONE of the JDK 1.8 instlalations are checked in the right-hand list, and when you select "JavaSE-1.8, you have the desired JDK 1.8 distribution checked in the right-hand list.

Related