70

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.

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.

<%@ 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>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user2130951
  • 2,601
  • 4
  • 31
  • 58
  • 2
    you have a error in jsp page so tomcat unable to compile – SpringLearner Oct 08 '13 at 09:09
  • 1
    Could you post your jsp file? mabbas is correct, you need to add this line in your jsp file. `<%@page import="java.util.Map.Entry"%>` – Vinoth Krishnan Oct 08 '13 at 09:22
  • 1
    The class format of JDK8 is changed the thats the reason why Tomcat is not able to compile JSPs. Try to get a newer version of Tomcat. See my answer below. – Aleš Nov 13 '13 at 00:05
  • This applies to all applications with an embedded compiler [in general](https://stackoverflow.com/q/26102115/2711488). – Holger Sep 20 '17 at 07:25

11 Answers11

97

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

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.

Brett Ryan
  • 26,937
  • 30
  • 128
  • 163
  • 23
    I was using Tomcat 7.0.54 with Java 8 and was getting this 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). So make sure you have a clean TC installation! – AtliB Jun 20 '14 at 15:34
  • 1
    It's working for me. Thank you. Download Tomcat here http://olex.openlogic.com/packages/tomcat/7.0.50 . – Sanjay Bhimani Jun 21 '14 at 04:56
  • 3
    Thanks to @AtliB ! Got same issue with Tomcat 7.55. Actually issue was due an old ecj-3.7.2.jar present in lib folder (imported while importing others libs). Removing it solved the problem :) – Cedric Simon Jul 31 '14 at 17:11
  • 3
    It's a shame that the Tomcat documentation says "Java X **or later**" for all versions of Tomcat when in reality, there is actually a limited range of Java versions that will work with a specific Tomcat version. – Burhan Ali Aug 13 '14 at 12:00
  • 1
    what worked for me was changing the version of tomcat7-maven-plugin from 2.0 to 2.2 – Jayz Mar 17 '15 at 14:08
  • Try setting jsp servlet to use target vm version as 1.8. Use http://censore.blogspot.in/2015/04/how-to-set-tomcat-7-source-level-to.html – biplav Apr 07 '15 at 06:52
  • I have a fresh CentOS instance where I installed tomcat7 7.0.54 which has `ecj3-7.0.54.jar`. Where else should I look for ecj jars as this one seems to be up-to-date? – Jayen Jan 14 '16 at 02:25
13

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.

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.

See following references:

Aleš
  • 8,896
  • 8
  • 62
  • 107
3

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.

    <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

Hasan K
  • 610
  • 8
  • 20
2

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.

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.

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.

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.

  • Thanks for the ECJ pointer. If someone is looking for ECJ jars, they can be found here http://mvnrepository.com/artifact/org.eclipse.jdt.core.compiler/ecj . Not all versions will work for your tomcat. I found the right version for mine on the jasper pom file http://repo2.maven.org/maven2/org/apache/tomcat/tomcat-jasper/7.0.52/tomcat-jasper-7.0.52.pom – djjeck Nov 06 '14 at 20:31
1

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.

nshweta
  • 499
  • 2
  • 7
  • 19
1

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

1

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.

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).

teobais
  • 2,820
  • 1
  • 24
  • 36
1

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.

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.)

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?

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

Ozan Aksoy
  • 306
  • 3
  • 6
1

I ran into this before, as others said: just upgrade jetty plugin

if you are using maven

go to jetty plugin in pom.xml and update it to

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.3.0.v20150612</version>
    <configuration>
        <scanIntervalSeconds>3</scanIntervalSeconds>
        <httpConnector>
            <port>${jetty.port}</port>
            <idleTimeout>60000</idleTimeout>
        </httpConnector>
        <stopKey>foo</stopKey>
        <stopPort>${jetty.stop.port}</stopPort>
    </configuration>
</plugin>

hope this help you

Basheer AL-MOMANI
  • 14,473
  • 9
  • 96
  • 92
0

Add this import <%@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

Community
  • 1
  • 1
Gyanendra Dwivedi
  • 5,511
  • 2
  • 27
  • 53
0

From the JIRA knowledge base:

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.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Engineer
  • 1,436
  • 3
  • 18
  • 33