6

New Maven projects created in Eclipse (on Windows) use the default JRE System Library "J2SE-1.5".

Default System Library in Maven Project

The project was created the following way:

  • New Project
  • Maven -> Maven Project
  • Archtype: maven-archetype-quickstart

I want to use the JDK 1.8.0, which is my default JDK for non Maven projects.

My JAVA_HOME variable is set to

C:\Program Files\Java\jdk1.8.0_152

I tried switching the system library via Right Click on the System Library and set the path to my JDK 1.8.0. But after a Maven update it resets back to the 1.5.

Other Stackoverflow questions just suggest to set the JAVA_HOME, but that did not work for me. Specify JDK for Maven to use

I looked for some POM.xml commands to set the library, but couldn't find anything. My POM looks pretty standard right now:

<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.test</groupId>
<artifactId>Test123</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Test123</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

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

What do I need to change to get the JDK 1.8 as my default Library?

Paul Erlenmeyer
  • 523
  • 2
  • 6
  • 29
  • What do you have in your `Java Build Path` in `Project>Properties` ? Did you change your `Java Compiler` to 1.8 too ? – Hearner Jul 31 '18 at 14:44
  • @Hearner The build path contains "JRE System Library [J2SE-1.5] and Maven Dependecies (only Junit inside) – Paul Erlenmeyer Jul 31 '18 at 14:50
  • [this answer](https://stackoverflow.com/a/41604839/424903) on the linked question is the easiest way to do it. The IDE should pick up the configuration from the pom, no need to manually configure it. – Gimby Jul 31 '18 at 14:53

3 Answers3

7

Set the JDK in the pom.xml:

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

in eclipse do a 'Maven->Update Project'

Chris
  • 158
  • 8
2

Open your Eclipse, click on

Windows -> Preferences -> Java -> Installed JREs

Verify that the checked JRE refers to the JDK you want. Otherwise, select the checked JRE and click Edit, and change the path to the JDK home.

gtgaxiola
  • 9,241
  • 5
  • 42
  • 64
  • 1
    There is the only entry: "jdk1.8.0". And that is beeing properly used in non Maven projects. – Paul Erlenmeyer Jul 31 '18 at 14:53
  • Thanks @PaulErlenmeyer. Check [this Answer](https://stackoverflow.com/questions/25592290/how-to-force-eclipse-m2e-plugin-to-use-jdk-for-a-project) To see if it helps – gtgaxiola Jul 31 '18 at 14:59
0

The following steps did the job for me on Windows:

  1. Set JAVA_HOME to the new JDK (necessary for Maven)
  2. Add the new JDK as runtime environment in Eclipse (Window/Preferences/Installed JRE’s) and set the new JDK as default
  3. Go to Window/Preferences/Installed JRE’s/Execution Environments and select the JavaSE version of the new JDK by clicking it. Select the new JDK as the default for that JavaSE version by filling the checkbox.
  4. Run Maven/Update Project for your project