无法为 JSP 编译类:无法解析类型 java.util.Map$Entry。它是从所需的 .class 文件间接引用的

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19243458/
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-12 15:22:51  来源:igfitidea点击:

Unable to compile class for JSP: The type java.util.Map$Entry cannot be resolved. It is indirectly referenced from required .class files

javajsptomcatservlets

提问by user2130951

I can't get tomcat7 to compile jsps. It till run the example servlets just fine and the service is up and running. I am running oracle java 8.

我无法让 tomcat7 编译 jsps。它直到运行示例 servlet 就好了并且服务启动并运行。我正在运行 oracle java 8。

Can anyone point me in the right direction?

任何人都可以指出我正确的方向吗?

Here is the stacktrace:

这是堆栈跟踪:

type Exception report

message Unable to compile class for JSP:

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 1 in the generated java file
The type java.util.Map$Entry cannot be resolved. It is indirectly referenced from required .class files

Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.35 logs.


The code looks like this and it's the sample code from tomcat7 so my guess is that it's correct.

代码看起来像这样,它是来自 tomcat7 的示例代码,所以我猜它是正确的。

<%@ taglib prefix="mytag" uri="/WEB-INF/jsp2/jsp2-example-taglib.tld" %>
<html>
<head>
  <title>JSP 2.0 Examples - Hello World SimpleTag Handler</title>
</head>
<body>
<h1>JSP 2.0 Examples - Hello World SimpleTag Handler</h1>
<hr>
<p>This tag handler simply echos "Hello, World!"  It's an example of
a very basic SimpleTag handler with no body.</p>
<br>
<b><u>Result:</u></b>
<mytag:helloWorld/>
</body>
</html>

采纳答案by Brett Ryan

You must use a more recent version of tomcat which has support for JDK 8.

您必须使用支持 JDK 8 的更新版本的 tomcat。

I can confirm that apache-tomcat-7.0.35 does NOT have support for JDK8, I can also confirm that apache-tomcat-7.0.50 DOES have support for JDK8.

我可以确认 apache-tomcat-7.0.35 不支持 JDK8,我也可以确认 apache-tomcat-7.0.50 确实支持 JDK8。

回答by Gyanendra Dwivedi

Add this import <%@page import="java.util.Map" %>

添加此导入 <%@page import="java.util.Map" %>

This worked for me, but I also needed to add <%@ page import="java.util.HashMap" %>. It seems that the above answer is true, that if you have the newer tomcat you might not need to add these lines, but as I could not change my whole system, this worked.
Thank you

这对我有用,但我还需要添加 <%@ page import="java.util.HashMap" %>。上面的答案似乎是正确的,如果您拥有较新的 tomcat,您可能不需要添加这些行,但是由于我无法更改我的整个系统,所以这行得通。
谢谢

回答by Engineer

From the JIRA knowledge base:

来自JIRA 知识库

Symptoms

Workflow actions may be inaccessible

  1. JIRA may throw exceptions on screen
  2. One or both of the following conditions may exist:

The following appears in the atlassian-jira.log:

     2007-12-06 10:55:05,327 http-8080-Processor20 ERROR [500ErrorPage] 
     Exception caught in500 page Unable to compile class for JSP
    org.apache.jasper.JasperException: Unable to compile class for JSP
   at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:572)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)

_

Cause:

The Tomcat container caches .java and .class files generated by the JSP parser they are used by the web application. Sometimes these get corrupted or cannot be found. This may occur after a patch or upgrade that contains modifications to JSPs.

Resolution

1.Delete the contents of the /work folder if using standalone JIRA or /work if using EAR/WAR installation . 2. Verify the user running the JIRA application process has Read/Write permission to the /work directory. 3. Restart the JIRA application container to rebuild the files.

Symptoms

工作流操作可能无法访问

  1. JIRA 可能会在屏幕上抛出异常
  2. 可能存在以下一种或两种情况:

以下内容出现在 atlassian-jira.log 中:

     2007-12-06 10:55:05,327 http-8080-Processor20 ERROR [500ErrorPage] 
     Exception caught in500 page Unable to compile class for JSP
    org.apache.jasper.JasperException: Unable to compile class for JSP
   at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:572)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)

_

Cause:

Tomcat 容器缓存由 Web 应用程序使用的 JSP 解析器生成的 .java 和 .class 文件。有时这些会损坏或无法找到。这可能发生在包含对 JSP 修改的补丁或升级之后。

Resolution

1.如果使用独立 JIRA 或 /work 如果使用 EAR/WAR 安装,则删除 /work 文件夹的内容。2. 验证运行 JIRA 应用进程的用户对 /work 目录具有读/写权限。3. 重启JIRA应用容器,重建文件。

回答by Ale?

The class format of JDK8 has changed and thats the reason why Tomcat is not able to compile JSPs. Try to get a newer version of Tomcat.

JDK8 的类格式发生了变化,这就是 Tomcat 无法编译 JSP 的原因。尝试获取更新版本的 Tomcat。

I recently had the same problem. This is a bug in Tomcat, or rather, JDK 8 has a slightly different class file format than what prior-JDK8 versions had. This causes inconsistency and Tomcat is not able to compile JSPs in JDK8.

我最近遇到了同样的问题。这是 Tomcat 中的一个错误,或者更确切地说,JDK 8 的类文件格式与以前的 JDK8 版本略有不同。这会导致不一致,Tomcat 无法在 JDK8 中编译 JSP。

See following references:

请参阅以下参考资料:

回答by user3480817

Because we are running on Ubuntu 12.04 LTS and the latest official supported tomcat7 package is 7.0.26 we are not easily able to update the whole tomcat.

因为我们在 Ubuntu 12.04 LTS 上运行,并且官方支持的最新 tomcat7 软件包是 7.0.26,所以我们无法轻松更新整个 tomcat。

I order to test for with the jdk8, I was able to get resolve this issue by changing some jars against their latest 7.0.* version.

我为了使用 jdk8 进行测试,我能够通过针对最新的 7.0.* 版本更改一些 jar 来解决此问题。

I switched jasper.jar, jasper-el and tomcat-util to the version 7.0.53 and added ecj-4.3.1.jar. That brings the application back online.

我将 jasper.jar、jasper-el 和 tomcat-util 切换到 7.0.53 版本并添加了 ecj-4.3.1.jar。这使应用程序重新联机。

BUT... also i changed packaged content with this, so maybe it would be better to download the whole tomcat and use it self installed as messing up packages. So please see this only as a very dirty quickhack or workaround.

但是......我也用这个改变了打包的内容,所以也许最好下载整个tomcat并使用它自己安装作为弄乱包。因此,请仅将此视为非常脏的快速黑客或解决方法。

回答by nshweta

Faced exactly the same issue while upgrading my application from java 6 to java 8 on tomcat 7.0.19. After upgrading the tomcat to 7.0.59, this issue is resolved.

在 tomcat 7.0.19 上将我的应用程序从 java 6 升级到 java 8 时遇到了完全相同的问题。将tomcat升级到7.0.59后,问题解决。

回答by Williams Tobi

Try and add <%@page import="java.util.Map.Entry"%>to your jsp file

尝试添加<%@page import="java.util.Map.Entry"%>到您的 jsp 文件中

回答by thodorisbais

There are a lot of correct/same answers, but for future references:

有很多正确/相同的答案,但供将来参考:

Same stands for Tomcat 7. Be aware that updating only your used frameworks' versions (as proposed in other similar questions) isn't enough.

同样代表 Tomcat 7。请注意,仅更新您使用的框架版本(如其他类似问题中所建议的)是不够的。

You also have to update Tomcat plugin's version. What worked for me, using Java 7, was upgrading to version 2.2 of tomcat7-maven-plugin (= Tomcat 7.0.47).

您还必须更新 Tomcat 插件的版本。使用 Java 7 对我有用的是升级到 tomcat7-maven-plugin(= Tomcat 7.0.47)的 2.2 版。

回答by Ozan Aksoy

I recently get across the same issue. I was using IntelliJx64 with Tomcat7.0.32 with jdk.8.0.102. There was no issue then. I was able to directly access my deployment localhost:[port]without adding [mywebapp]or /ROOT.

我最近遇到了同样的问题。我将 IntelliJx64 与 Tomcat7.0.32 与 jdk.8.0.102 一起使用。那时没有问题。我能够直接访问我的部署localhost:[port]而不添加[mywebapp]/ROOT

When I tried to migrate to eclipse neon, I came across the same bug that is discussed when I tried to set the path as empty string. When I enforced execution environment to Java7 and set modules to empty it did not solve toe issue. However, when I changed my tomcat installation to 7.072 and manually changed context path configuration to path="" the problem was solved in eclipse. (You can manipulate the path via double click server and switching to module tab too.)

我尝试迁移到 eclipse neon 时遇到了在尝试将路径设置为空字符串时讨论的相同错误。当我将执行环境强制为 Java7 并将模块设置为空时,它并没有解决脚趾问题。但是,当我将我的 tomcat 安装更改为 7.072 并手动将上下文路径配置更改为 path="" 时,问题在 eclipse 中解决了。(您也可以通过双击服务器并切换到模块选项卡来操作路径。)

My wonder is how come IntelliJ was not giving any issues with the same bug which was supposed to be related to tomcat installation version?

我想知道为什么 IntelliJ 没有给出任何应该与 tomcat 安装版本相关的相同错误的问题?

There also seems to be a relation with the IDE in use.

似乎也与使用的 IDE 有关系。

回答by Hasan K

If you are using maven then you can add the tomcat7-maven-plugin to your pom.xml and it shall run fine. This plugin will run the project on Tomcat servlet container version 7.0.47 which supports JDK 1.8.

如果您使用的是 maven,那么您可以将 tomcat7-maven-plugin 添加到您的 pom.xml 中,它应该可以正常运行。该插件将在支持 JDK 1.8 的 Tomcat servlet 容器版本 7.0.47 上运行该项目。

    <plugins>
    <plugin>
     <groupId>org.apache.tomcat.maven</groupId>
     <artifactId>tomcat7-maven-plugin</artifactId>
     <version>2.2</version>
     <configuration>
<!-- Include context file for Datasource configuration -->
     <contextFile>./src/main/webapp/META-INF/context.xml</contextFile>
    <port>8080</port>
     </configuration>
     <dependencies>
<!-- Include jdbc driver dependency if using datasource (in my case oracle) -->
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.4.0</version>
    </dependency>
  </dependencies>
    </plugin>
    </plugins>

Hope this is useful! Thanks

希望这是有用的!谢谢