Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven 3.5 issue with JDK 9

Tags:

maven

java-9

I am using Maven 3.5.0 and JDK 9 build 171. When I tried to compile my project I got an exception:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile (default-compile) on project admin: Fatal error compiling: ja-va.lang.NoClassDefFoundError: com/sun/tools/javac/file/BaseFileObject: com.sun.tools.javac.file.BaseFileObject 

I added suggested flags to the MAVEN_OPTS but without success:

--add-opens jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED

Any suggestions?

like image 402
Sergiy Avatar asked Jun 06 '17 11:06

Sergiy


People also ask

What is the minimum version of Java for Maven?

1 for LTS) requires Java 6 thus Maven jobs must be launched with a JDK >= 6. Jenkins >= 1.612 (1.625. 1 for LTS) requires Java 7 thus Maven jobs must be launched with a JDK >= 7.

What version of Java does Maven support?

The default Java compiler version used by Maven is Java 1.5 . Why that is still the default Java compiler version is a good question, since Java 5 was released in 2004.

Does Maven work with OpenJDK?

You can't configure OpenJDK 11, you can configure maven to use java11, whether it will use Oracle Java or OpenJDK depends on which of the two is installed in your system and configured in your ide (or path, if you are using CLI). maven.apache.org/plugins/maven-compiler-plugin/examples/… You can't set it in the pom.

Does Maven work with Java 8?

2.1. The Maven compiler accepts this command with –target and –source versions. If we want to use the Java 8 language features, the –source should be set to 1.8. Also, for the compiled classes to be compatible with JVM 1.8, the –target value should be 1.8. The default value for both of them is the 1.6 version.


2 Answers

Verify Java version used by Maven is correct.

Run mvn -v this will show which java version maven is using.

For me, Maven was using Java 15, but my application was intended to run on Java 8. Setting JAVA_HOME to path for jdk8 fix the issue.

like image 64
Niket Shah Avatar answered Sep 29 '22 13:09

Niket Shah


Upgrading the lombok version to 1.18.0 may fix your issue.

Check here. They fixed the issue in 1.18.0 version

like image 24
Vijay Shegokar Avatar answered Sep 29 '22 12:09

Vijay Shegokar