4

I can't seem to get tomcat to compile the jsp files it should serve. It will run .war files and servlets perfectly fine. But will fail on any jsp page. I am getting the impression it does not find the regular java includes.

I am trying with this file (or any other jsp test file included)

<%@ page  language="java" import="java.util.*" errorPage="" %>
<html>
<body>
Current Date time: <%=new java.util.Date()%>
</body>
</html>


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.

log:

Oct 30, 2013 4:56:12 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/tomcat-demo] threw    exception [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:] with root cause
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:
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at  org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:200)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:724)



This is the ps axf for this process.
 9277 ?        Sl     0:23 /usr/lib/jvm/java-8-oracle/bin/java -
 Djava.util.logging.config.file=/var/lib/tomcat7/conf/logging.properties -
 Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC -Dbuild.compiler=javac -
 Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -
 Djava.endorsed.dirs=/usr/share/tomcat7/endorsed -classpath 
 /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar -
 Dcatalina.base=/var/lib/tomcat7 -Dcatalina.home=/usr/share/tomcat7 -
 Djava.io.tmpdir=/tmp/tomcat7-tomcat7-tmp org.apache.catalina.startup.Bootstrap start
user2130951
  • 2,601
  • 4
  • 31
  • 58
  • Do you have required imports (if you are using list (or) arraylist etc.,)? – kosa Oct 30 '13 at 14:52
  • Check log file in logs folder and see there any clues. – kosa Oct 30 '13 at 14:55
  • Added info about the test file and parts of the catalina.out. do you need any other log info? – user2130951 Oct 30 '13 at 14:59
  • Any idea why tomcat can't seem to compile any JSP ? – user2130951 Oct 30 '13 at 15:34
  • It seems servlet.jar classpath issue. Which IDE you are using? – kosa Oct 30 '13 at 15:35
  • It's directly from the tomcat7 server. Not using any ide. That's why it's so confusing since it's running perfectly and also run .war files. – user2130951 Oct 30 '13 at 15:38
  • 1
    If not using any IDE, why eclipse plugin details are there in log? – kosa Oct 30 '13 at 15:42
  • You are right. That's unrelated and me that has read the log wrong. Running an eclipse .war file also that is working but sometimes generates an error in the catch (). corrected the log output – user2130951 Oct 30 '13 at 15:58
  • org.apache.jasper.compiler.ErrorDispatcher.javacError. It seems some jar with this class file is missing in classpath. – kosa Oct 30 '13 at 16:35
  • probably true. Need to find some info on how to set the correct classpath. I don't understand why it's not correct since it's starting up and running servlets perfectly. – user2130951 Oct 30 '13 at 16:58
  • 2
    I would like to point out that it is most probably Tomcat 7 and Java 8 issue, as explained here http://stackoverflow.com/questions/19243458/tomcat7-not-compiling-jsp-examples – Rade_303 Mar 23 '15 at 10:08

3 Answers3

11

Tomcat 7.0.35 and java 8 don't play well together, so use a recent version of Tomcat and the ECJ module, that bug is fixed by now.

Tomcat Version 7.0.50 and ECJ 4.3.1 (or newer) should work. See JBoss Ticket as mentioned in the comments by @AtliB.

flob
  • 3,760
  • 2
  • 34
  • 57
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Mathias Müller Jan 24 '14 at 15:47
  • The answer is 'Use a recent version of Tomcat, you encountered a bug that is now fixed.'... no need for clarification. – flob Jan 27 '14 at 09:17
  • I still get this error, even with tomcat 7.0.52, using the packages of ubuntu 14.04 on ubuntu 12.04. – Bruno Medeiros May 05 '14 at 21:14
  • I'm using Tomcat 7.0.54 with Java 8 and I'm getting this as well – AtliB Jun 20 '14 at 15:19
  • I was using Tomcat 7.0.54 with Java 8 and was getting this error even then. Turned out I had an old ecj-3.7.1.jar (the compiler tomcat uses) in the lib folder (from an older installation). Removing that .jar file fixed this problem for me (tomcat used ecj-P20140317-1600.jar instead). – AtliB Jun 20 '14 at 15:32
  • More details on this can be found here: https://bugzilla.redhat.com/show_bug.cgi?id=1080026 – AtliB Jun 20 '14 at 15:35
  • If you dont wanna update tomcat then maybe try http://censore.blogspot.in/2015/04/how-to-set-tomcat-7-source-level-to.html to point tomcat7 to point to Java8 – biplav Apr 07 '15 at 06:53
1

I was just struggling with a very similar problem. For me it turned out that I was running Tomcat with a "tomcat7" user, but "root" was the owner of many of the tomcat files and directories. After I changed "tomcat7" to own everything in the tomcat directory (recursively) it started working for me.

Allen
  • 11
  • 1
0

For me it was the answer @AtliB provided. The problem is in the jar compiler. I installed Tomcat by dropping one folder in another. Same filenames were overwritten, but not the ones with version numers :(. So I had Multiple ecj-x.x files. And Tomcat just loads the first one it sees. Deleting the old ones left me ecj-4.4.jar, which works like a charm on java 8!

Ibanezje
  • 21
  • 5