Error when using logmanager (l4j2) and Java 8 (java.lang.reflect.annotatedelement cannot be resolved)

When I switched the JDK version of a new project from 7u45 to 8u20, I encountered a strange error At the beginning of my class, a harmless logmanager declaration was rejected with the following error:

The type java.lang.reflect.AnnotatedElement cannot be resolved. It is indirectly referenced from required .class files

This is the code:

public class Class1 {   
    private static Logger log = LogManager.getLogger(Class1.class); 
    ...

Eclipse advised me to configure the build path, but I had no idea what to configure because I didn't know the root problem of the error

Using JDK and version 7, everything is normal

Solution

When using JDK 8 and IDE with its own compiler (such as eclipse), you must update the IDE to a version with Java 8 support, even if you are not using newer Java 8 features

The reason is that the compiler must be able to load the newer class files of JRE in order to compile the software that references these classes

Sometimes, when it ignores newer versions of class files, it can use an older compiler But some types confuse the old class file parser because they use new features, especially annotatedelement, which now has a default method, while map Entry is an interface that now has static methods

It seems that eclipse will not find differences in references that cannot find class files, and class files cannot be read when "« classname » cannot be resolved"

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>