JSP Compilation Errors on Red Hat Enterprise Linux 4

How to fix JSP Compilation Errors on Red Hat Enterprise Linux 4.

The Tomcat 5.5 package for RHEL 4 (tomcat5-5.5.23-0jpp_4rh.9) uses an older version of the Eclipse Java Compiler than the one that comes with the vanilla version of Tomcat 5.5.23. This causes it to be unable to compile JSPs that use Java 5 features. When compilation fails an error like the following will be logged to /var/log/tomcat5/catalina.out:

2009/10/30 11:46:04:757 GMT [ERROR] [jsp] - Servlet.service() for servlet jsp threw exception
<org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 4 in the jsp file: /francis.jsp
Type mismatch: cannot convert from Integer to int
1: <%
2: // Test JSP that will only work with Java 5 because it relies out autoboxing
3: Integer i = new Integer(42);
4: int i2 = i;
5: %>
6: i2 = <%= i2 %>


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

An error occurred at line: 4 in the jsp file: /francis.jsp
Type mismatch: cannot convert from Integer to int
1: <%
2: // Test JSP that will only work with Java 5 because it relies out autoboxing
3: Integer i = new Integer(42);
4: int i2 = i;
5: %>
6: i2 = <%= i2 %>


Stacktrace:
        at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
        at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
        at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:435)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)

To fix, replace the Java compiler and related Tomcat jars with the versions from the vanilla Apache distribution of Tomcat :

  • delete jasper5-compiler.jar, jdtCompilerAdapter.jar and jdtcore.jar from /usr/share/tomcat5/common/lib
  • download apache-tomcat-5.5.23.tar.gz and untar (tar xvzf apache-tomcat-5.5.23.tar.gz)
  • copy jasper-compiler.jar and jasper-compiler-jdt.jar from vanilla apache-tomcat-5.5.23/common/lib to /usr/share/tomcat5/common/lib
  • if /usr/share/tomcat5/common/lib/tools.jar exists then delete it (it is the Sun Java compiler and will cause problems if it is from JDK 1.4)
  • restart Tomcat: /etc/init.d/tomcat5 restart

Was this article helpful?

Yes No

Thanks for your feedback!