Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change JDK in Maven Projects (Eclipse)

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?

like image 775
Paul Erlenmeyer Avatar asked Jul 31 '18 14:07

Paul Erlenmeyer


2 Answers

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'

like image 137
Chris Avatar answered Sep 22 '22 16:09

Chris


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.

like image 34
gtgaxiola Avatar answered Sep 24 '22 16:09

gtgaxiola