You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by "Julien, Timothy" <TJ...@Bluestone.com> on 2001/03/22 02:27:06 UTC

jasper's -classpath

How does Jasper construct its Classpath when compiling jsps?

>From what I see it is:

System class path + something from Tomcat + the directory containing the jsp
source.

Note that when running Jasper in another container, the 'something from
Tomcat' part is null - an init-parameter 'org.apache.cataline.jsp_classpath'
for JspServlet, I think, is (obviously) missing when running in another
container.

Question: Would Jasper be able to run out of a web-app, without hanving it
in the system classpath?  Could I stick all of Jaspers relevant jars in the
WEB-INF/lib directory and get it to work?  The behavior I am seeing says no.

I would think that the classpath for compilation should include the jars in
WEB-INF/lib directory.

Tim Julien
HP middleware

Re: jasper's -classpath

Posted by Mel Martinez <me...@yahoo.com>.
--- "Julien, Timothy" <TJ...@Bluestone.com> wrote:
> How does Jasper construct its Classpath when
> compiling jsps?
> 
> From what I see it is:
> 
> System class path + something from Tomcat + the
> directory containing the jsp
> source.
> 
> Note that when running Jasper in another container,
> the 'something from
> Tomcat' part is null - an init-parameter
> 'org.apache.cataline.jsp_classpath'
> for JspServlet, I think, is (obviously) missing when
> running in another
> container.
> 


When running in another container, the class path
visible to jasper JSP's is like so:

0 - Classpath (via system class loader)
1 - classes visible to JspServlet's class loader (i.e.
the servlet class loader for the container)
2 - classes visible to JasperLoader (the class loader
used to load Jsp servlets after they have been
compiled).

In general, you may or may not have control over 0
(depends on how the container starts up) and what is
available via (1) depends on how the container loads
servlets.  The control over (2) is a little shaky
currently.

The classpath available to JasperLoader for loading
classes is basically whatever directories, jar or zip
files have been added via the addJar() method. 
Unfortunately, as near as I can tell, this is not done
anywhere.

Now the classpath that is pulled out of the
JspServlet's init-params looks like it is _supposed_
to be added to JasperLoader, but if it is I can't find
where.  It IS appended to the classpath used by the
Compiler to compile the jsp's .java files into .class
files, but that doesn't help you load the classes and
run them.

Before I got involved with the tomcat project
directly, I solved this problem by extending a few
jasper classes to refactor it and fix this and a few
other problems specifically to address running Jasper
in a non-tomcat container (I need to run it in
WebLogic as well).  In my solution, I did two things.
(1) I outright added a system property to set a
classpath for the jsp loader.  (2) I calculate the
classpath for the JasperLoader using the above
property as well as the heretofore ignored init-param
and make sure to add it to the loader when I construct
the loader for the particular page (my implementation
uses a loader for each page to support dynamic
reloading).

So somewhere between the creation of the loader and
the  attempt to load the class, which currently
happens in JspServlet.doLoadJSP(), the classpath needs
to be added to the loader.

I say 'currently' because Costin is right when he says
that jasper could use some refactoring.  I'd like to
propose some wholesale refactoring of the class model
for the JspServlet and it's supporting classes to
better partition responsibilities.  I'll make a more
formal proposal along these lines shortly.

> Question: Would Jasper be able to run out of a
> web-app, without hanving it
> in the system classpath?  Could I stick all of
> Jaspers relevant jars in the
> WEB-INF/lib directory and get it to work?  The
> behavior I am seeing says no.
> 
> I would think that the classpath for compilation
> should include the jars in
> WEB-INF/lib directory.
> 

If the container properly implements the spec, then
JspServlet and thus the jsp servlets should be able to
'see' the WEB-INF/lib classes for LOADING purposes via
the servlet classloader.  However, that classpath is
not made available to the compiler for COMPILATION
currently.  The compiler sees the classpath of the
JasperLoader.getClassPath() call (which as I've said
above, is not necessarily set because that is
initialized via missing addJar() calls) catenated to
the init-param classpath.
  
So the result is that currently, you can only LOAD
classes that the parent servlet classloader can see
and you can only COMPILE classes visible in the
init-param classpath.  If you know how the container's
classloader behaves, and also manually setup the
init-param classpath, you can work around this
confusion.

However, this needs to be fixed.  I will try to take a
stab at first a short-term fix to get it working right
in the next couple of days and then as mentioned, I'd
like to propose some more wholesale changes.  Note - a
lot of these problems don't exist with the
JspInterceptor.  These problems seem to be solely with
the JspServlet as used separately from tomcat.

Cheers,

Dr. Mel Martinez


__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/