-->

JSP compilation error using TomEE Embedded and Jav

2019-05-25 05:46发布

问题:

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)

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>

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?

回答1:

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

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.

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>