无法解析 java.io.ObjectInputStream 类型。它是从所需的 .class 文件间接引用的

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36963248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 18:52:14  来源:igfitidea点击:

The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files

javaeclipsejakarta-eeobjectinputstreambuildpath

提问by user3891270

I have downloaded Eclipse and tried to create a sample servlet program but I got following error

我已经下载了 Eclipse 并尝试创建一个示例 servlet 程序,但出现以下错误

The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files

无法解析 java.io.ObjectInputStream 类型。它是从所需的 .class 文件间接引用的

I have configured build path correctly. I am using Java 8 and Apache Tomcat 7 and libraries for both are referenced correctly.

我已经正确配置了构建路径。我正在使用 Java 8 和 Apache Tomcat 7,并且它们的库都被正确引用。

Problem is specifically for Java EE only. Ordinarily Java SE projects are running fine.

问题仅针对 Java EE。通常 Java SE 项目运行良好。

回答by AmitB10

same problem with me. This is not a solution but a workaround, which worked for me: Buildpath->Configure buildpath->Libraries-> Here remove the JRE system library pointing to JRE8 and add JRE system library for JRE7.

我也有同样的问题。这不是解决方案,而是一种变通方法,对我有用:Buildpath->Configure buildpath->Libraries-> 此处删除指向 JRE8 的 JRE 系统库并为 JRE7 添加 JRE 系统库。

回答by metin.n

Using the latest 7.x Tomcat (currently 7.0.69) solved the problemfor me.

使用最新的 7.x Tomcat(目前为 7.0.69)为我解决了这个问题

We did also try a workaround in a old eclipse bug, maybe that did it's part to solve the problem, too?

我们也尝试过解决旧的 Eclipse 错误,也许这也是解决问题的一部分?

https://bugs.eclipse.org/bugs/show_bug.cgi?id=67414

https://bugs.eclipse.org/bugs/show_bug.cgi?id=67414

Workaround:

解决方法:

  • Window->Preferences->Java->Installed JREs
  • Uncheck selected JRE
  • Click OK (this step may be optional?)
  • Check JRE again
  • Window->Preferences->Java->Installed JREs
  • 取消选中选定的 JRE
  • 单击确定(此步骤可能是可选的?)
  • 再次检查 JRE

回答by Phoenix

Workaround:

解决方法:

Window-> Preferences-> Java-> Installed JREs, select a different JRE

Window-> Preferences-> Java-> Installed JREs,选择不同的 JRE

maybe this JDK edition is not suitable:

也许这个JDK版本不适合:

enter image description here

在此处输入图片说明



So try this one instead:

所以试试这个:

enter image description here

在此处输入图片说明

Problem solved!

问题解决了!

回答by mzjn

Something happened in Java 8 Update 91 that broke existing JSP code. That seems pretty clear. Here is a sample of similar questions and bug reports:

Java 8 Update 91 中发生了一些破坏现有 JSP 代码的事情。这似乎很清楚。以下是类似问题和错误报告的示例:

All these are about problems with Java 8 Update 91 (or later) that are not present when using earlier JRE/JDK versions.

所有这些都是关于 Java 8 Update 91(或更高版本)的问题,这些问题在使用早期 JRE/JDK 版本时不存在。



The following OpenJDK changeset from 22 January 2016 appears to be related: http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/rev/32f64c19b5fb(commit message "8144430: Improve JMX connections"). The changeset seems to be related to this vulnerability, https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2016-3427, which is mentioned in a comment to this Red Hat bug report, https://bugzilla.redhat.com/show_bug.cgi?id=1336481.

以下来自 2016 年 1 月 22 日的 OpenJDK 变更集似乎相关:http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/rev/32f64c19b5fb(提交消息“8144430:改进 JMX 连接”)。变更集似乎与此漏洞有关,https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2016-3427 ,在对此 Red Hat 错误报告的评论中提到,https ://bugzilla.redhat.com/show_bug.cgi?id=1336481

The Update 91 release notes document mentions JDK-8144430 (non-public ticket): http://www.oracle.com/technetwork/java/javase/8u91-relnotes-2949462.html.

Update 91 发行说明文档提到了 JDK-8144430(非公开票):http: //www.oracle.com/technetwork/java/javase/8u91-relnotes-2949462.html

In "Oracle Critical Patch Update Advisory - April 2016", the CVE-2016-3427 vulnerability is mentioned: http://www.oracle.com/technetwork/security-advisory/cpuapr2016v3-2985753.html.

在“Oracle 重要补丁更新咨询 - 2016 年 4 月”中,提到了 CVE-2016-3427 漏洞:http: //www.oracle.com/technetwork/security-advisory/cpuapr2016v3-2985753.html

回答by Ismael Sarmento

You simply need to upgrade your Tomcat version, to Tomcat 8.0.xx. Java8 <-> Tomcat8

您只需将 Tomcat 版本升级到 Tomcat 8.0.xx。 Java8 <-> Tomcat8

This is the configuration that I have been using and it has always worked out well JDK versionTomcat versions

这是我一直在使用的配置,它一直运行良好 JDK版本Tomcat 版本

回答by Gavy

Upgrading to tomcat 7.0.70 resolved the issue for me

升级到 tomcat 7.0.70 为我解决了这个问题

回答by Touhid

I was also facing same issue. I had Jdk1.7.0.79. Then I updated it with Jdk8.0.120. Then the problem solved. After successful completion of upgraded jdk. Go to project->clean. It will rebuild the project and all red alert will be eliminated.

我也面临同样的问题。我有 Jdk1.7.0.79。然后我用Jdk8.0.120更新了它。然后问题就解决了。升级jdk后顺利完成。转到项目-> 清洁。它将重建项目并消除所有红色警报。

回答by kaixas K

Okay, this question was a year ago but I recently got this problem as well.

好的,这个问题是一年前的,但我最近也遇到了这个问题。

So what I did :

所以我做了什么:

  1. Update tomcat 7 to tomcat 8.
  2. Update to the latest java (java 1.8.0_141).
  3. Update the JRE System Library in Project > Properties > Java Build Path. Make sure it has the latest version which in my case is jre1.8.0_141 (before it was the previous version jre1.8.0_111)
  1. 将 tomcat 7 更新为 tomcat 8。
  2. 更新到最新的 java (java 1.8.0_141)。
  3. Project > Properties > Java Build Path 中更新 JRE 系统库。确保它具有最新版本,在我的情况下是 jre1.8.0_141(在之前的版本 jre1.8.0_111 之前)

When I did the first two steps it still doesn't remove the error so the last step is important. It didn't automatically change the build path for jre.

当我执行前两个步骤时,它仍然没有消除错误,因此最后一步很重要。它没有自动更改 jre 的构建路径。

回答by Aniket Thakur

I am using Google appengine java sdk and was facing similar issue. I had to add

我正在使用 Google appengine java sdk 并面临类似的问题。我不得不添加

<runtime>java8</runtime>

in appengine-web.xml file to make it work.

在 appengine-web.xml 文件中使其工作。

回答by mohsen.nour

Reason : Old versions of Tomcat 6 JSP compiler don't seem to be aware of JDK 8 constant pool enhancements - eg. method handles. New code in JDK 8u is using a method handle instead of creating an anonymous class. This will cause the method handle to be listed in the constant pool and the eclipse compiler will choke on this - https://bz.apache.org/bugzilla/show_bug.cgi?id=56613

原因:旧版本的 Tomcat 6 JSP 编译器似乎不知道 JDK 8 常量池增强 - 例如。方法句柄。JDK 8u 中的新代码使用方法句柄而不是创建匿名类。这将导致方法句柄被列在常量池中,并且 eclipse 编译器将对此感到窒息 - https://bz.apache.org/bugzilla/show_bug.cgi?id=56613