8进行JSP编译错误

8进行JSP编译错误

本文介绍了使用TomEE Embedded和Java 8进行JSP编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试访问在TomEE Embedded中运行的基本JSP文件时,我收到内部服务器错误,并显示以下错误消息:

When trying to access a basic JSP file running in TomEE Embedded, I get an internal server error with the following error message:

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

An error occurred at line: [1] in the generated java file: [/tmp/apache-tomee814337484264703144/work/Tomcat/localhost/sample/org/apache/jsp/index_jsp.java]
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:103)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:485)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:379)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:662)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)

我正在使用Java 8和(当前)最新版本的TomEE Embedded(1.7.2)。这些是我的POM文件中的依赖项:

I'm using Java 8 and the (currently) most recent version of TomEE Embedded (1.7.2). These are the dependencies in my POM file:

<dependencies>
    <dependency>
        <groupId>org.apache.openejb</groupId>
        <artifactId>tomee-embedded</artifactId>
        <version>1.7.2</version>
    </dependency>
</dependencies>

这个问题与我的JSP文件的内容无关,因为它基本上是空的:

The issue is not related to the contents of my JSP file, as it's mostly empty:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Sample</title>
</head>
<body>
    <h1>Sample</h1>
</body>
</html>

有没有人遇到过同样的问题?有没有人有解决方法?

Has anyone experienced the same issue? Does anyone have a workaround?

推荐答案

经过一些研究和实验,我自己想出来了。

After some more research and experimenting, I figured it out myself.

以防有人遇到同样的问题:似乎问题与TomEE用于编译JSP文件的Eclipse Java编译器(3.5.2)的版本有关。由于Java 8中的类格式发生了一些变化,因此旧版本的编译器似乎感到困惑。

Just in case someone encounters the same issue: it seems that the issue is related to the version of the Eclipse Java compiler (3.5.2) that's being used by TomEE to compile the JSP files. Since there were some changes to the class format in Java 8, older versions of the compiler seem to get confused.

我已经引入了更新版本的Eclipse Java编译器(4.4.2)并从TomEE中排除旧编译器,现在一切都按预期工作:

I've pulled in a more recent version of the Eclipse Java compiler (4.4.2) and excluded the old one from TomEE, and now everything is working as expected:

<dependencies>
    <dependency>
        <groupId>org.apache.openejb</groupId>
        <artifactId>tomee-embedded</artifactId>
        <version>1.7.2</version>
        <exclusions>
            <exclusion>
                <groupId>org.eclipse.jdt.core.compiler</groupId>
                <artifactId>ecj</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jdt.core.compiler</groupId>
        <artifactId>ecj</artifactId>
        <version>4.4.2</version>
    </dependency>
</dependencies>

这篇关于使用TomEE Embedded和Java 8进行JSP编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 18:31