Change JDK in Maven Projects (Eclipse)

Paul Erlenmeyer :

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?

Chris :

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'

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=93464&siteId=1