Hello,

This is my first post.

Is this the correct forum to discuss a feature request?

I have been doing some work recently with running tomcat with the use
of special class loaders.  For some of what I am doing it is useful to
configure web apps to use the parent class loader because doing so
makes it easy to instrument the classes for coverage reports and other
benefits.  One area where I had trouble with has been to load JSP
classes using parent class loader delegation.  The current Tomcat 6/7
codebase does not seem to provide an option to change the way
JasperLoader treats classes that reflect JSP code.  I want these
classes to follow the general class loader rules so I can instrument
code that I create prior to the launch of tomcat and then use this for
a special run to capture information with code coverage reports for
JSP classes.

I have made the change in my local system via a hack to introduce a
property in JasperLoader to enable me to at times configure it to
delegate to the parent class loader.  My feeling is that this is
something that others may find useful at some point and as such I am
supplying the following tiny little patch.  The patch does not change
the default behavior of the loader in any way but it allows a user to
set a JVM property to configure jasper to use parent class loader for
jsp files.  Conceptually this seems similar to other options and while
rare it is something that I think someone else might find useful at
some point.

There may be other and better ways to achieve similar results but
after doing some research I could not find a solution for this without
creating the patch.

-Mark

--- a/java/org/apache/jasper/servlet/JasperLoader.java
+++ b/java/org/apache/jasper/servlet/JasperLoader.java
@@ -39,6 +39,10 @@ public class JasperLoader extends URLClassLoader {
     private PermissionCollection permissionCollection;
     private ClassLoader parent;
     private SecurityManager securityManager;
+       private static final boolean alwaysUseParentClassLoader;
+       static {
+               alwaysUseParentClassLoader =
Boolean.parseBoolean(System.getProperty("org.apache.jasper.servlet.JasperLoader.alwaysUseParentClassLoader",
"false"));
+       }

     public JasperLoader(URL[] urls, ClassLoader parent,
                         PermissionCollection permissionCollection) {
@@ -120,7 +124,7 @@ public class JasperLoader extends URLClassLoader {
             }
         }

-        if( !name.startsWith(Constants.JSP_PACKAGE_NAME + '.') ) {
+        if( !name.startsWith(Constants.JSP_PACKAGE_NAME + '.') ||
alwaysUseParentClassLoader) {
             // Class is not in org.apache.jsp, therefore, have our
             // parent load it
             clazz = parent.loadClass(name);

-Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to