tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joe Emenaker" <>
Subject Re: Loading applet from a subdirectory of WEB-INF
Date Sun, 29 Oct 2000 21:39:15 GMT
> my problem is that the applet and some servlets use the same bean
> classes. When the applet is loaded and it refers to bean classes the
> location of the loaded applet is used to search for the bean classes
> thus the applest must reside in a directory that the bean classes can
> found. Any ideas what I could do?

The easiest thing to do would be to just make a symbolic link (you *ARE*
doing this in a unix-like OS, right?!!?!?) from somewhere in your normal
webapp directory to your WEB-INF/classes or WEB-INF/lib.

Of course, this has security concerns. Someone with a web browser could
now get to all of your servlet classes and inspect them. This might be
unaaceptable. In that case, you might be able to make a symbolic link to
a *sub*directory in WEB-INF/lib. Perhaps something like
"WEB-INF/lib/shared" and make a symlink to that in the directory where
your normal web files reside. Two reasons why this might not work: 1) If
you're using a Windows machines, this almost certainly won't work
because I haven't seen any Windows OS that does symbolic links. 2) The
Tomcat documentation says something to the effect of "any jar files in
WEB-INF/lib will be put in the classpath of the classloader for that
context..." but it doesn't say if it recurses into subdirectories. In
other words, if the classloader would find "WEB-INF/lib/myclass.jar",
I'm unsure whether or not it would find
"WEB-INF/lib/shared/myclass.jar". My hunch is that this wouldn't
work.... but, if you're on a unix-like OS, it's very quick and easy to
try, which is why I mention it.

Looking at the servlet 2.2 spec, it does not appear that there's
anything that you can put in web.xml to append classpaths. Darn.

Here's a solution that I can almost guarantee will work. The drawback is
that it doesn't lend itself well to upgrading tomcat because you're
going to have to modify the tomcat source and recompile.

Basically, you have to search through to sourcecode and find where
tomcat reads in the info about your contexts and then searches through
WEB-INF/lib. Somewhere, there will be a method that, when given a path,
will return a list of all of the jar files in that directory or
whatever. You'll need to find where tomcat is calling that method with
something like "...mywebapp/WEB-INF/lib" and add a line so that it
*also* looks in some other directory at the root of your webapp, like
"mywebapp/shared" or something. Then, any classes you drop into
mywebapp/shared would be found by your servlets... and tomcat would
serve the jars up as normal files, as well. You can do the same trick
with your "unjarred" WEB-INF/classes directory, too.

- Joe

View raw message