Greg W.F.R
Greg W.F.R

Reputation: 734

module jdk.compiler does not "opens com.sun.tools.javac.processing" to unnamed module @4bae33a6

I cloned this Project from Github

https://github.com/PacktPublishing/Java-Machine-Learning-for-Computer-Vision.git

I am going to use the FaceRecognizition from this project. But as soon as I try to run this in IntelliJ I get this error

java: java.lang.ExceptionInInitializerError Unable to make field private com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors com.sun.tools.javac.processing.JavacProcessingEnvironment.discoveredProcs accessible: module jdk.compiler does not "opens com.sun.tools.javac.processing" to unnamed module @4bae33a6

What can I do?

Upvotes: 30

Views: 81461

Answers (6)

jorge aldo perez
jorge aldo perez

Reputation: 1

Try with another java version, I was getting same issue after mvn install command,then I switch the java version of my IDE,from java 17 to java 1.8 enter image description here

and went fine, then I was able to generate the jar file, in case you want to install with java 17 , align your pom or gradle file to java 17 version, check latest version for all the dependencies

-Windows -IDE:intelliJ -java version:17 -new java version:8 -maven -springboot 3

Upvotes: 0

Sandeep Deb
Sandeep Deb

Reputation: 194

Unfortunately this error can have multiple causes, but all caused due to the compatibility issues between the JDK used for compilation and the dependent libraries.

To learn the exact cause, run maven with -e or -X switch. This will produce the stack trace pointing the exact incompatibility issue. Post this, you can change the JDK version and/or upgrade/downgrade the library.

In my case it was lombok (trace below). I had to upgrade the version from 1.16.xx to 1.18.28 for it to compile.

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors com.sun.tools.javac.processing.JavacProcessingEnvironment.discoveredProcs accessible: module jdk.compiler does not "opens com.sun.tools.javac.processing" to unnamed module @4ed56cfd
    at java.lang.reflect.AccessibleObject.checkCanSetAccessible (AccessibleObject.java:354)
    at java.lang.reflect.AccessibleObject.checkCanSetAccessible (AccessibleObject.java:297)
    at java.lang.reflect.Field.checkCanSetAccessible (Field.java:178)
    at java.lang.reflect.Field.setAccessible (Field.java:172)
->  at lombok.javac.apt.LombokProcessor.getFieldAccessor (LombokProcessor.java:116)
->  at lombok.javac.apt.LombokProcessor.<clinit> (LombokProcessor.java:108)
    at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)
    ...

Upvotes: 7

Mahesh Revaskar
Mahesh Revaskar

Reputation: 104

In my case, I had to upgrade Lombok dependency version and then the issue was resolved.

Upvotes: 2

Radhakrishnan
Radhakrishnan

Reputation: 1040

For me, the problem is the Lombok version.

After upgradation from java8 to java17 and from lombok version 1.18.6 to 1.18.26

Old one:

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.6</version>
    <scope>provided</scope>
</dependency>

Upgraded one for java17

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.26</version>
    <scope>provided</scope>
</dependency>

Upvotes: 44

ionyekanna
ionyekanna

Reputation: 440

Set your IDE to use the right version of SDK and that resolved it for me.

Upvotes: 0

Govind Kalyankar
Govind Kalyankar

Reputation: 624

I had same issue first check what Java version is used by maven by using

mvn -v

if it is set to Jdk 16 then you will have to update file below

/usr/local/Cellar/maven/{version}/bin/mvn

and set

JAVA_HOME:-$(/usr/libexec/java_home)

then you can confirm by running mvn -v again

Above steps have resolved the issue for me

Upvotes: 23

Related Questions