Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Maven, Eclipse, and Java 9

DZone's Guide to

Maven, Eclipse, and Java 9

Eclipse users who use Maven are used to the M2E plugin issue of having your JRE reset on you. But there's an additional gotcha between Java 8 and Java 9.

· Java Zone ·
Free Resource

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

TL;DR: Eclipse users who use Maven are used to the M2E plugin issue of having your JRE reset on you. But there's an additional gotcha between Java 8 and Java 9. Read on for the details.

Anyone that uses the M2E(maven-to-eclipse) plugin in eclipse knows the issue where you have run a build, then update maven on your project only to have it reset the JRE and throw up a wall of project errors! I noticed the issue in the post I made on running Java EE 8 with Java 9 using Open Liberty

The solution is to ensure the compiler is running the correct version you require, so -

<properties>
   <maven.compiler.source>1.8</maven.compiler.source>
   <maven.compiler.target>1.8</maven.compiler.target>
   <failOnMissingWebXml>false</failOnMissingWebXml>
</properties>


Or -

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


There is a further point worth noting if you are using Java 9 or later, as the version number format is different. So while Java 8 has a version of 1.8, Java 9 has a version of 9 -

Image title

Java 9 vs Java 8 versions

This means you need to state the version in your pom as -

 <properties>
   <maven.compiler.source>9</maven.compiler.source>
   <maven.compiler.target>9</maven.compiler.target>
   <failOnMissingWebXml>false</failOnMissingWebXml>
 </properties>


Or using the full version in my JavaEE8 project(https://github.com/farrelmr/javaee8/blob/master/pom.xml) this would be stated as -

<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.javabullets.javaee8</groupId>
 <artifactId>javaee8</artifactId>
 <version>1.0-SNAPSHOT</version>
 <packaging>war</packaging>
 <dependencies>
  <dependency>
   <groupId>javax</groupId>
   <artifactId>javaee-api</artifactId>
   <version>8.0</version>
   <scope>provided</scope>
  </dependency>
 </dependencies>
 <build>
  <finalName>javaee8</finalName>
 </build>
 <properties>
  <maven.compiler.source>9</maven.compiler.source>
  <maven.compiler.target>9</maven.compiler.target>
  <failOnMissingWebXml>false</failOnMissingWebXml>
 </properties>
</project>


This will prevent the problem in eclipse

This post may seem obvious - but it is worth stating that the change in version number for Java 9 means you must check you are using the correct version number in maven.

Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. Our APIs verify, standardize, and correct the Big 4 + more – name, email, phone and global addresses – to ensure accurate delivery, prevent blacklisting and identify risks in real-time.

Topics:
java ,java 8 ,java 9 ,maven ,eclipse ,plugin

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}