Return-Path: Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 15432 invoked from network); 9 Feb 2001 23:15:22 -0000 Received: from nsqw.olliance.com (HELO mail.olliance.com) (63.150.52.11) by h31.sny.collab.net with SMTP; 9 Feb 2001 23:15:22 -0000 Received: from dhcp-100.sfo.lan ([10.1.1.100] helo=olliance.com ident=jason) by mail.olliance.com with esmtp (Exim 3.12 #1 (Debian)) id 14RMlF-0000WX-00 for ; Fri, 09 Feb 2001 15:15:29 -0800 Message-ID: <3A847AD6.2080401@olliance.com> Date: Fri, 09 Feb 2001 15:18:46 -0800 From: Jason Brittain Organization: Olliance Inc. User-Agent: Mozilla/5.0 (X11; U; Linux 2.2.16-3 i686; en-US; 0.7) Gecko/20010105 X-Accept-Language: en MIME-Version: 1.0 To: tomcat-dev@jakarta.apache.org Subject: [PATCH] TC4: TomcatBlock on Avalon 3.1a1: Part 2 (for real this time) Content-Type: multipart/mixed; boundary="------------090307080907010001050306" X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N --------------090307080907010001050306 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Last time I forgot to attach the diffs! Sorry.. This mail has them. Attached are the diffs to the files that I modified to make TomcatBlock (Tomcat 4 running on Avalon 3.1a1). Explanation: build.xml (the top-level build.xml file) I moved the dist-opt-avalon target (and associated stuff) to this file since to build the bar file it needs to copy stuff from Catalina, Jasper, and webapps. catalina/build.xml Removed the dist-opt-avalon target from this file, added some more lines about only compiling Avalon-dependent source if Avalon is present. catalina/src/share/org/apache/catalina/core/ContainerBase.java I needed to fix an obscure bug in this file to get AvalonFileLogger to work. What was happening was: When one of the class loaders starts up, it tries to log some things in some cases. But, its logger has not yet been started yet, so the class loader ends up throwing an exception (can't remember what kind). To fix this, I switched the startup order: the loader's logger gets started first, then the loader that uses it gets started. I'm not real sure how this could have worked properly before this patch. :) catalina/src/share/org/apache/catalina/startup/Bootstrap.java This one's the tough one! I had a hard time getting Jasper to work inside the TomcatBlock, even after the block deployed all of the usual directories to the filesystem. This is because Jasper needs the JDK's tools.jar on its classpath. When you run Catalina from the command line (stand-alone), the startup script catalina.sh puts tools.jar on the classpath: if [ -f "$JAVA_HOME/lib/tools.jar" ] ; then CP=$CP:"$JAVA_HOME/lib/tools.jar" fi But, when starting from Avalon, you don't have the shell script to add it to the classpath for you. So, I figured all I needed to do was have TomcatBlock create its own ClassLoader that adds tools.jar (and maybe some other jars too) and start up the Bootstrap class just like CatalinaBlock did, but load it from the ClassLoader that TomcatBlock created. So, I tried that. It didn't work. After tearing out some hair, I found the problem. Bootstrap's createCommonLoader() method creates a new StandardClassLoader with a set of URLs (an array of them) like this: StandardClassLoader loader = new StandardClassLoader(array); This constructor of StandardClassLoader makes a new StandardClassLoader with the array of URLs (to jars or other paths) setting the default parent class loader as its parent, instead of setting Bootstrap's ClassLoader as its parent. This caused Jasper to not use the class loader I created to give it access to tools.jar, thus making Jasper not work. Now, if there is some good reason to deliberately not make Bootstrap's classloader the parent class loader of the common class loader, then my patch needs to be reworked. But, I couldn't think of any reasons. And, I could think of reasons why you would want to make Bootstrap's class loader the parent of the common class loader.. In the classloader.html doc, it says that the "Common" class loader's parent is supposed to be the "System" class loader (that is to say, the class loader created from the contents of CLASSPATH at runtime). When you run Tomcat stand-alone, this is indeed what happens. I guess the "System" class loader is the "default" parent, so it works. But, when TomcatBlock created its own class loader, that new class loader is not the default, so it's never the parent of the "Common" class loader, so there is no way of adding tools.jar (or other jars) to the Common class loader's search path. I suppose this is only a problem when you're trying to start up Catalina using Bootstrap the way we need to in order to make the Avalon Block. Someone else suggested that I use EmbeddedTomcat instead, but from what I understand that means that I also must implement my own config system, which I don't really want to do. :) So, what my patch to Bootstrap does: it uses Bootstrap's own class loader as the parent of the Common class loader. And, when you run in stand-alone mode, this is (conveniently) the System class loader. My next mail shows the files I added..... -- Jason Brittain Software Engineer, Olliance Inc. http://www.Olliance.com Current Maintainer, Locomotive Project http://www.Locomotive.org --------------090307080907010001050306 Content-Type: text/plain; name="main-build.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="main-build.diff" --- build.xml Fri Feb 9 14:53:03 2001 +++ build.xml-new Fri Feb 9 12:00:40 2001 @@ -8,11 +8,13 @@ - - + + + + @@ -53,6 +55,8 @@ + @@ -142,7 +146,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --------------090307080907010001050306 Content-Type: text/plain; name="catalina-build.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="catalina-build.diff" --- build.xml Fri Feb 9 14:56:29 2001 +++ build.xml-new Fri Feb 9 14:56:22 2001 @@ -8,7 +8,6 @@ - @@ -107,7 +106,11 @@ unless="jdbcse.present" /> - + + @@ -262,24 +265,6 @@ - - - - - - - - - - - - - - - - - - --------------090307080907010001050306 Content-Type: text/plain; name="ContainerBase.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ContainerBase.diff" --- ContainerBase.java Fri Feb 9 12:17:41 2001 +++ ContainerBase.java-new Fri Feb 9 12:23:48 2001 @@ -1031,10 +1031,10 @@ started = true; // Start our subordinate components, if any - if ((loader != null) && (loader instanceof Lifecycle)) - ((Lifecycle) loader).start(); if ((logger != null) && (logger instanceof Lifecycle)) ((Lifecycle) logger).start(); + if ((loader != null) && (loader instanceof Lifecycle)) + ((Lifecycle) loader).start(); if ((manager != null) && (manager instanceof Lifecycle)) ((Lifecycle) manager).start(); if ((realm != null) && (realm instanceof Lifecycle)) --------------090307080907010001050306 Content-Type: text/plain; name="Bootstrap.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="Bootstrap.diff" --- Bootstrap.java Fri Feb 9 13:38:57 2001 +++ Bootstrap.java-new Fri Feb 9 14:04:21 2001 @@ -228,7 +228,22 @@ // Construct the class loader itself String array[] = (String[]) list.toArray(new String[list.size()]); - StandardClassLoader loader = new StandardClassLoader(array); + ClassLoader parent = null; + try { + + Class c = Class.forName("org.apache.catalina.startup.Bootstrap"); + parent = c.getClassLoader(); + + } catch (ClassNotFoundException e) { + + e.printStackTrace(); + + } + StandardClassLoader loader = null; + if (parent != null) + loader = new StandardClassLoader(array, parent); + else + loader = new StandardClassLoader(array); return (loader); --------------090307080907010001050306--