Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse 2021-06: ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module

Upgrading to the last Eclipse version, now I am getting the following error:

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 @5d01b0d8

I tried changing JDK under preferences with no luck.

like image 215
devwebcl Avatar asked Jun 24 '21 14:06

devwebcl


People also ask

Does eclipse 2021-09 support Java 17?

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.

Why can't I run Java 8 programs in Eclipse?

This issue of mine is only with the JVM used to run Eclipse. An increasing number of platform plugins have moved to Java 11, so the Eclipse IDE is now unusable with a Java 8 JVM. You may however still use the IDE to develop Java 8 and indeed Java 5 applications.

How do I change the default Java version in Eclipse?

An easy way is to change the Java Version used to run Eclipse. There for you have to change the eclipse.ini. Set the vm location at the start of the file to a prior Java 16 JDK e.g. JDK 14 Under MacOSX eclipse.ini is typically located in /Applications/Eclipse.app/Contents/Eclipse/

Why can't I run eclipse with Lombok?

If you are using Lombok, it's probably this issue: twitter.com/howlger/status/1407316561803763716 (changing the JDK under preferences, does not change the Java used to run Eclipse). Or a similar issue of a plugin you have installed. Thanks, @howlger it was Lombok plug-in when using JDK 16.


2 Answers

Thanks, @howlger it was Lombok plug-in when using JDK 16. That tweet gave me the reasons: https://github.com/projectlombok/lombok/issues/2810

A workaround :

  • Use Java 15 to start Eclipse or
  • add --illegal-access=warn and --add-opens java.base/java.lang=ALL-UNNAMED to your eclipse.ini
  • or install a pre-built version (1.18.21)

In my situation I had to change eclipse.ini VM path:

-vm
C:\bin\jdk-15.0.2\bin
like image 114
devwebcl Avatar answered Sep 17 '22 00:09

devwebcl


An easy way is to change the Java Version used to run Eclipse. There for you have to change the eclipse.ini.

  1. Set the vm location at the start of the file to a prior Java 16 JDK e.g. JDK 14
  2. Under MacOSX eclipse.ini is typically located in /Applications/Eclipse.app/Contents/Eclipse/
  3. The reason is an incompatibility of the lombock plugin

This a working example of the eclipse.ini file:

-vm
/Library/Java/JavaVirtualMachines/jdk-14.0.2.jdk/Contents/Home/bin/java
-startup
../Eclipse/plugins/org.eclipse.equinox.launcher_1.6.200.v20210416-2027.jar
--launcher.library
../Eclipse/plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_1.2.200.v20210527-0259
-product
org.eclipse.epp.package.java.product
-showsplash
org.eclipse.epp.package.common
--launcher.defaultAction
openFile
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-javaagent:/Applications/Eclipse.app/Contents/Eclipse/lombok.jar
-Dosgi.requiredJavaVersion=11
[email protected]/eclipse-workspace
-Dsun.java.command=Eclipse
-XX:+UseG1GC
-XX:+UseStringDeduplication
--add-modules=ALL-SYSTEM
-Dorg.eclipse.swt.internal.carbon.smallFonts
-Dosgi.dataAreaRequiresExplicitInit=true
-Dorg.eclipse.swt.graphics.Resource.reportNonDisposed=true
-Xms256m
-Xmx2048m
-Xdock:icon=../Resources/Eclipse.icns
-XstartOnFirstThread
like image 24
Mirko Ebert Avatar answered Sep 19 '22 00:09

Mirko Ebert