Add support for using extension classes in custom JSP pages
|Reported by:||Nicklas Nordborg||Owned by:||Nicklas Nordborg|
An extensions that uses custom JSP pages are currently limited to use only classes from JAR file installed in
WEB-INF/lib. It can't use classes from it's own JAR file. The reason is simply that Tomcat doesn't know about the extension JAR files in
WEB-INF/extensions. The current workaround for extensions that need custom classes is to place a second JAR file in
WEB-INF/lib that contains those classes. The drawback is that this requires a restart.
I have tested a few ideas with varying results. There is one that I got to work.
- We have to remap the servlet for *.jsp. We can use the same servlet as Tomcat uses, but we have to specify another compiler. This can be done in
- The compiler should override the default compiler and needs to check the request path. If it is in the
/extensionsdirectory the compiler must extract the JARNAME from the path, and create a classloader for it. Then, it replaces the classloader Tomcat's compiler with the JARFILE classloader.
- The drawback with this solution is that the class we specify as a compiler must be in a JAR that is located in Tomcat's internal lib-directory. This also means that the compiler code doesn't have direct access to the BASE core classes. Fortunately it has access to the classloader Tomcat uses for BASE and can use reflection to access the BASE core classes. The code is not pretty though.
Note! Since this solution requires special installation of JAR files into Tomcats internal directories, I think this should be optional. It only needs to be installed if an extension requires it. I am also a bit unsure of compatibility with future versions of Tomcat. The JSP compiler is not part of any specification so we are really hooking into code that is specific for Tomcat. This solution will probably not work for other servlet containers.