Eclipse not able to open java files -> Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass
Asked Answered
P

11

19

Getting the following error, after adding Lombok lib

An error has occurred. See error log for more details.
Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @1d1c37d5
Protostele answered 17/9, 2021 at 5:20 Comment(3)
You tagged your question with both, [java-17] and [eclipse-2021-09]. Since Eclipse 2021-09 does not support Java 17, I guess you have installed Java 17 Support for Eclipse 2021-09 (4.21) which is the preview/BETA of the upcoming Java 17 support that will be released with Eclipse 2021-12 (4.22) on December 15, 2021. Please make sure this issue has been reported to Eclipse with a minimal reproducible example and the error log.Dawndawna
JDK 17 doesn’t support --illegal-access=permit anymore. It’s not is if the previous versions weren’t warning about this kind of access…Marine
In my case, I had to change eclipse.ini VM path: -vm C:\bin\jdk-11.0.18\bin as suggested by https://mcmap.net/q/146048/-eclipse-2021-06-classformaterror-accessible-module-java-base-does-not-quot-opens-java-lang-quot-to-unnamed-moduleSkippet
P
23

Add the below lines to the end of the eclipse.ini file

--illegal-access=warn
--add-opens=java.base/java.lang=ALL-UNNAMED
Protostele answered 17/9, 2021 at 15:43 Comment(12)
Since your question is specifically mentioning Java 17, there is no point in specifying --illegal-access=warn, it is not supported and will be ignored.Marine
But it’s working on Java 17, I did adding Lombok lib, after that I got the problem. Same problem I faced with 2021-06 in Java 15Protostele
@Protostele Your question seems to be about running your code and your answer seems to be about running Java. It's unclear whether you installed the preview Java 17 support and whether you use a Java 17 VM to run Eclipse. Please improve or delete your question.Dawndawna
Thank you! This solved my issue when trying to run Eclipse 2021-09 (with lombok) on macOS with JDK 17 installed. Without this fix Eclipse will indeed start and run, but every imported Maven Project is broken and gives the error from the question. I spent literally a whole day with reinstalling different Eclipse versions, reimporting the projects, choosing different JDKs within Eclipse, with and without lombok, etc... Nothing worked. But adding those 2 lines to eclipse.ini solved it.Austerity
@BenjaminM So it's a Lombok thing? I cannot find a Lombok issue. How to reproduce this issue (with which Java version running Eclipse and with which Lombok version)? With or without Java 17 Support for Eclipse 2021-09 (4.21) installed?Dawndawna
@Protostele did you crosscheck? When your computer works after you connected the power plug and painted it green, does it prove that painting it green solved the problem? How about adding the --add-opens java.base/java.lang=ALL-UNNAMED option without the --illegal-access=warn that has no effect?Marine
@Holger, I don't know why or how it worked, I just copied these lines from the Github eclipse repository issue. To recreate the issue-> Install eclipse -> import gradle/maven project -> Install Lombok -> restart eclipse. You will get an error.Protostele
“I just copied these lines”—a very good summarization of why we are flooded with horrible software. Even now, after I told you explicitly that these are two independent options and only one of them has an effect in JDK 17, you refuse to even try to understand. Yes, without green color and the cable removed, the computer doesn’t work, but with cable plugged in and a green painting, the computer works. Now, you only have to understand that this does not imply that green painting was necessary. Or just execute jdk-17\bin\java --illegal-access=warn x in cmd and note the warning message.Marine
@Dawndawna I'm not sure if it's a Lombok issue. I did not get an error when importing a fresh Spring Boot application, but when importing my projects from work (all using Spring Boot 2.5.4 with lot's of different dependencies: Hibernate, Jackson, Elasticsearch, MongoDB, MySQL, Freemarker, etc.). My machine is running Eclipse 2021-09 (4.21.0), Lombok 1.18.20, macOS 11.6, OpenJDK 17 (2021-09-14 LTS).Austerity
@BenjaminM With which Java version do you run Eclipse? Java 17 that is installed on your system or Java 16 that is included in Eclipse? Please tell, in eclipse.ini what is the line after -vm. Please check also if there is something in the error log. This would at least be hints on how to produce the issue.Dawndawna
Adding those two lines to my ini caused Eclipse to now even being able to start any more. It instantly says Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.Black
Don't works with Eclipse IDE for Enterprise Java and Web Developers Version: 2023-09 (4.29.0) Build id: 20230907-1323. Only works setting that value on each uni test methodLossa
W
29

Updating to Lombok 1.18.22 plugin resulted in this issue going away for me. I did try adding the --add-opens flag, but the eclipse launcher balked at that. IMHO this is simply a result of incompatibility between Java 17 and the Lombok Eclipse IDE plugin.

Whipping answered 23/12, 2021 at 6:47 Comment(6)
even using lombok 1.18.24 my project will not run... :/Tripoli
Hmmmmm. I am a bit stumped. What version of Eclipse is that?Whipping
My issue occurred after installing the lombok jar. It was older version - 1.18.4 Updating to latest (1.18.24) helped resolve the issue.Kassiekassity
my issue also go resolved by upgrading and following this link "youtube.com/watch?v=VR7VaiXHJEY"Need
So, Is the downgrade plugin the solution?Lossa
Yes, but updated to 1.18.30 for my caseMindy
P
23

Add the below lines to the end of the eclipse.ini file

--illegal-access=warn
--add-opens=java.base/java.lang=ALL-UNNAMED
Protostele answered 17/9, 2021 at 15:43 Comment(12)
Since your question is specifically mentioning Java 17, there is no point in specifying --illegal-access=warn, it is not supported and will be ignored.Marine
But it’s working on Java 17, I did adding Lombok lib, after that I got the problem. Same problem I faced with 2021-06 in Java 15Protostele
@Protostele Your question seems to be about running your code and your answer seems to be about running Java. It's unclear whether you installed the preview Java 17 support and whether you use a Java 17 VM to run Eclipse. Please improve or delete your question.Dawndawna
Thank you! This solved my issue when trying to run Eclipse 2021-09 (with lombok) on macOS with JDK 17 installed. Without this fix Eclipse will indeed start and run, but every imported Maven Project is broken and gives the error from the question. I spent literally a whole day with reinstalling different Eclipse versions, reimporting the projects, choosing different JDKs within Eclipse, with and without lombok, etc... Nothing worked. But adding those 2 lines to eclipse.ini solved it.Austerity
@BenjaminM So it's a Lombok thing? I cannot find a Lombok issue. How to reproduce this issue (with which Java version running Eclipse and with which Lombok version)? With or without Java 17 Support for Eclipse 2021-09 (4.21) installed?Dawndawna
@Protostele did you crosscheck? When your computer works after you connected the power plug and painted it green, does it prove that painting it green solved the problem? How about adding the --add-opens java.base/java.lang=ALL-UNNAMED option without the --illegal-access=warn that has no effect?Marine
@Holger, I don't know why or how it worked, I just copied these lines from the Github eclipse repository issue. To recreate the issue-> Install eclipse -> import gradle/maven project -> Install Lombok -> restart eclipse. You will get an error.Protostele
“I just copied these lines”—a very good summarization of why we are flooded with horrible software. Even now, after I told you explicitly that these are two independent options and only one of them has an effect in JDK 17, you refuse to even try to understand. Yes, without green color and the cable removed, the computer doesn’t work, but with cable plugged in and a green painting, the computer works. Now, you only have to understand that this does not imply that green painting was necessary. Or just execute jdk-17\bin\java --illegal-access=warn x in cmd and note the warning message.Marine
@Dawndawna I'm not sure if it's a Lombok issue. I did not get an error when importing a fresh Spring Boot application, but when importing my projects from work (all using Spring Boot 2.5.4 with lot's of different dependencies: Hibernate, Jackson, Elasticsearch, MongoDB, MySQL, Freemarker, etc.). My machine is running Eclipse 2021-09 (4.21.0), Lombok 1.18.20, macOS 11.6, OpenJDK 17 (2021-09-14 LTS).Austerity
@BenjaminM With which Java version do you run Eclipse? Java 17 that is installed on your system or Java 16 that is included in Eclipse? Please tell, in eclipse.ini what is the line after -vm. Please check also if there is something in the error log. This would at least be hints on how to produce the issue.Dawndawna
Adding those two lines to my ini caused Eclipse to now even being able to start any more. It instantly says Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.Black
Don't works with Eclipse IDE for Enterprise Java and Web Developers Version: 2023-09 (4.29.0) Build id: 20230907-1323. Only works setting that value on each uni test methodLossa
N
7

The only thing that worked for me was downloading the lombok directly from lombok website instead of using the one available on maven folder.

Nephelometer answered 20/12, 2021 at 16:50 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Octodecillion
G
2

In my case, I solved changing java version from 16 top 11.
Adding this line:
--illegal-access=warn
--add-opens java.base/java.lang=ALL-UNNAMED

in my case, eclipse is not enable to start. Version: 2021-03 (4.19.0) Build id: 20210312-0638

Gingili answered 4/9, 2022 at 10:28 Comment(2)
Answer could be explained to help future readers. Why does adding this line help resolve the issue?Schlenger
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Octodecillion
J
1

Itseems problem with the lombok plugin. I have removed it from the eclipse.ini file and it resolved the issue.

Removed below line:

-javaagent:C:\<location>\eclipse-jee-2022-03-R-win32-x86_64\lombok.jar
Jorin answered 28/3, 2022 at 17:31 Comment(0)
L
1

I was also facing same issue after configured lombok in STS 4.17.2.RELEASE.

I have removed below properties from ini file.

--add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.base/sun.nio.ch=ALL-UNNAMED
--add-opens=java.base/java.net=ALL-UNNAMED
--add-opens=java.base/sun.security.ssl=ALL-UNNAMED
-Dsun.java.command=SpringToolSuite4

I have tried many solutions but not worked. So, I have compared with my older sts version.

Honestly, I don't know actual reason.

Lesslie answered 15/2, 2023 at 7:30 Comment(0)
S
0

For my case nothing above work for a specific project.

  1. Import existing maven project or create a maven project
  2. Goto project explorer and Right click on your pom.xm then select Run As maven install.
  3. and then what you want.

Hope it will serve your purpose. You can download a sample spring boot project from sample spring boot project

Or you can run a maven project from terminal or cmd. Just goto project root folder and then run a maven task like maven clean install . Happy Coding :)

Saltcellar answered 26/4, 2022 at 21:9 Comment(0)
C
0

you would need to check which java exe your IDE is pointing to in the .ini file. In other words, Just point your eclipse.ini to the right java.exe folder then the error goes away. This works for me in Spring STS and "may be" this same remedy will work in Eclipse too.

Chimera answered 27/2, 2023 at 0:27 Comment(0)
R
0

I had the same issue that mentioned above. When I downloaded new version of lombok.jar, it resolved my issue.

Rebak answered 21/9, 2023 at 14:57 Comment(0)
T
0

In MyCase I have added the above 2 lines in .ini file and I changed the Java version from 1.8 to 11 then it's start working

Tudor answered 22/2 at 11:35 Comment(2)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Wabble
You wrote (in your answer): I have added the above 2 lines in .ini file Pardon me, but what two lines are you referring to and do you mean the eclipse.ini file? Also, maybe you can edit your answer and post the lines that you changed in the .ini file ?Woods
R
-1

Yes! it is working for me, I added the only two lines

--illegal-access=warn;
--add-opens=java.base/java.lang=ALL-UNNAMED

in eclipse.ini file (SpringTooSuit4.ini for STS); now my STS and eclipse are working fine.

Rhoades answered 12/4 at 7:45 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Octodecillion

© 2022 - 2024 — McMap. All rights reserved.