tags:

views:

81

answers:

2

We have a large web app installation, using Apache/Tomcat/Jasper and jboss. In development environment, JSPs are compiled on the fly. Unfortunately, there is one package in particular that the on-the-fly compilation cannot seem to import. For some of the classes, using fully-qualified references rather than imports works, but not for all. All the classes in question are in a single jar (nonEjb.jar). Pre-compiling the JSPs works fine, but it's of course very painful to have to do that every time we need to change one of the affected files. This problem has existed for quite some time, and I'd really like to resolve it as I'm set to do some work in the affected area.

Here is a small test page. It fails for the first import. The two classes being imported are very similar, the only significant difference is their package placement. (And yes, I've verified that the package declarations are correct for both classes.)

<%@ page contentType="text/html; charset=utf-8" %>
<%@ page errorPage="/error.jsp" %>

<%@ page import="com.elementk.lms.product.otr.OtrProviderType" %>
<%@ page import="com.elementk.lms.product.course.CourseType" %>

<html>
<body>
<hr>
Displaying the page...
<br>
<%= OtrProviderType.B24x7_PROVIDER.getId() %> value
<br>
<%= CourseType.SELF_STUDY.getId() %> value
</hr>
</body>
<html>

Result:

09 Mar 2010 21:29:40,555 ERROR [K] [RequestTimingFilter.doFilter:65] Unable to compile class for JSP:

An error occurred at line: 6 in the generated java file
The import com.elementk.lms.product.otr cannot be resolved

I get the same error if I remove the import and fully-qualify the reference (as com.elementk.lms.product.org.OtrProviderType).

What might be causing the JSP compiler to locate one of the classes but not the other?

A: 

Where is the nonEjb.jar located? The compilation error suggests that it is not in the classpath (I assume that the package/classname is 100% correct and available in this JAR).

It should be placed in at least Webapp/WEB-INF/lib to get JSP to recognize it. An alternative location is Tomcat/lib, but this requires full admin control over the server and the JAR file would be accessible by all deployed webapps on the appserver.

BalusC
Both referenced classes are in the same jar (along with a large number of other classes). This is a large web app that's been around for a number of years, so I can guarantee that it's not an issue with the jar not being in the classpath. I'm wondering now whether there's something about the package name, and will next try renaming the package.
JST
+1  A: 

We finally determined why this was happening. Apparently, the on-the-fly compiler doesn't differentiate case, and the package com.elementk.lms.product contains a class named Otr. The compiler couldn't tell the difference between the package "com.elementk.lms.product.otr" and the class "com.elementk.lms.product.Otr". This explains why the error message only cites "com.elementk.lms.product.otr" even when the originating import was "com.elementk.lms.product.otr.OtrProviderType".

We had to repair by essentially avoiding the problem: we renamed the package.

JST
Thank you very much! We had the same problem and couldn't understand why only one of our packages kept giving this annoying error 'The import cannot be resolved'. We renamed the class :)
Frans