简体   繁体   中英

Tomcat Unable to compile class for JSP in Servlet 3.0

I have created Servlet with this archetype: http://maciejwalkowiak.github.io/servlet3-maven-archetype/

mvn archetype:generate \
  -DarchetypeGroupId=pl.maciejwalkowiak \
  -DarchetypeArtifactId=servlet3-webapp-archetype \
  -DarchetypeVersion=1.0.1

then I add index.jsp into src/main/webapp directory

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>hello, world</h1>
</body>
</html>

when I run mvn tomcat7:run and open http://127.0.0.1/mycontext/index.jsp

this error occurs:

HTTP Status 500 - Unable to compile class for JSP:

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:469)
    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:722)

what is the problem?

Update

I'm using java8 but I have following maven-compiler configuration in my maven:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>

You should double check your Tomcat version. Tomcat 7.0.32 contains a jar that is not fully compatible with Java 8, so upgrading your Tomcat version might help. Take a look at this .

Which JDK are you using? If it's 8 you will have to update Tomcat to 8 as well. If that's not the case, you should try going to the Project menu and select Clean... from there. Then try also cleaning the Server and the Server Working folder by selecting these options from the right click menu.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM