Laird Nelson wrote:

> Thanks to others' help and some digging, I discovered that having
> struts.jar in your classpath is a bad thing.  :-)  I know it says this
> in the documentation, but I was not aware of what the symptoms would be.
>

It's in the documentation for a reason :-).

>
> In short, for those who are still curious, if you have struts.jar in
> your regular classpath, then the tomcat start scripts find ActionMapping
> in *that* .jar file *instead of*, quite obviously, the struts.jar your
> web app should contain.  Since in that case ActionMapping is loaded by a
> non-Tomcat classloader, then any class loads it's asked to perform (like
> the one that takes place in createActionInstance()) don't know squat
> about the web application involved, and so you get a
> ClassNotFoundException.
>
> It seems like this sort of thing could be solved by (a) my reading the
> documentation and my environment settings more carefully (as always) or
> (b) by using something like Thread.get/setContextClassLoader() (I think
> that's the right call) instead of Class.forName() (which is almost
> always a bad idea) and making sure that *any* class load uses the tomcat
> thread class loader by default, without going up the parent classloader
> chain (as it would seem that there is no real use for it, right?).
>

Thread.setContextClassLoader is a Java2 thing.  That used to be an issue for
Struts, but is no longer since we decided to go with a Java2 minimum platform.

However, there is a much more serious issue involved here.  Doing this would
depend on the servlet container calling Thread.setContextClassLoader() for you,
and passing its webapp class loade as an argument.  This is *not* required by
the servlet specification, and will therefore *not* be portable.

(Just as an additional note, I did some experiments along the lines you are
suggesting, trying to make "struts.jar on the system classpath" work correctly.
It *still* doesn't work right with the XML parsers I tried, even on a servlet
container that calls setContextClassLoader the way I wanted.)

Moral of the story -- Struts depends on itself being loaded with the webapp
class loader.  Stick "struts.jar" in your WEB-INF/lib directory and stop
worrying about class loading ... :-)

>
> Anyhow, caveat programmor.
>
> Cheers,
> Laird
>

Craig


Reply via email to