在 Java 8 中使用 LogManager (l4j2) 时出错(无法解析 java.lang.reflect.AnnotatedElement) [英] Error when using LogManager (l4j2) with Java 8 (java.lang.reflect.AnnotatedElement cannot be resolved)

查看:35
本文介绍了在 Java 8 中使用 LogManager (l4j2) 时出错(无法解析 java.lang.reflect.AnnotatedElement)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在我的一个新项目的 JDK 版本从 7u45 切换到 8u20 时遇到了一个奇怪的错误.我的课程开始时无害的 LogManager 声明被拒绝,并显示以下错误:

I just encountered a strange error when switching the JDK version of a new Project of mine from 7u45 to 8u20. A harmless LogManager declaration at the beginning of my class is being refused with the following error:

无法解析 java.lang.reflect.AnnotatedElement 类型.它是从所需的 .class 文件间接引用的

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

这是代码:

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

Eclipse 建议我配置构建路径,但我不知道要配置什么,因为我不知道该错误的潜在问题.

Eclipse proposes me to configure the build path, but I have no Idea what to configure because I don't know the underlying problem of that error.

使用版本 7 的 JDK,一切正常.

Using the JDK with version 7, everything works fine.

推荐答案

当使用 JDK 8 和 IDE(或任何其他代码处理工具/框架)及其自己的编译器(如 Eclipse)时,您必须将工具更新为支持 Java 8 的版本,即使您没有使用较新的 Java 8 功能.

When using JDK 8 and an IDE (or any other code processing tool/framework) with its own compiler, like Eclipse, you have to update the tool to a version with Java 8 support, even if you are not using the newer Java 8 features.

原因是编译器必须能够加载 JRE 的较新类文件才能编译引用这些类的软件.

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

有时,当旧编译器忽略类文件的较新版本号时,您可以逃脱.但是某些类型会在使用新功能时混淆旧的类文件解析器,特别是 AnnotatedElement,现在有 default 方法和 Map.Entry,一个 interface 现在有 静态方法.

Sometimes you can get away with an older compiler when it ignores the newer version number of the class files. But some types will confuse older class file parsers as they use new features, notably AnnotatedElement, which now has default methods, and Map.Entry, an interface which now has static methods.

似乎 Eclipse 在找不到类文件的引用和它在说«classname» 无法解析"时无法读取的类文件之间没有区别.

It seems that Eclipse does not make a difference between references for which no class file could be found and class files it failed to read when saying "«classname» cannot be resolved".

这同样适用于所有使用 ECJ 作为嵌入式编译器的工具和框架.

The same applies to all tools and frameworks using ECJ as embedded compiler.

这篇关于在 Java 8 中使用 LogManager (l4j2) 时出错(无法解析 java.lang.reflect.AnnotatedElement)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆