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
--- build.xml Fri Feb 9 14:53:03 2001 +++ build.xml-new Fri Feb 9 12:00:40 2001 @@ -8,11 +8,13 @@ <property name="tomcat.dist" value="${basedir}/dist"/> <property name="webapps.build" value="${basedir}/webapps/build"/> <property name="webapps.dist" value="${basedir}/webapps/dist"/> - <property name="catalina.deploy" value="${tomcat.build}"/> <property name="jasper.deploy" value="${tomcat.build}"/> <property name="webapps.deploy" value="${tomcat.build}"/> - + <property name="avalon.dist" value="../avalon"/> + <property name="tomcat.bar" value="tomcat-avalon-bar"/> + <property name="avalon.deploy" value="${tomcat.dist}"/> + <property name="tomcat.version" value="tomcat-4.0"/> <!-- ===================== DEPLOY: Create Directories =================== --> <target name="deploy-prepare"> @@ -53,6 +55,8 @@ <!-- ====================== DIST: Create Directories ==================== --> <target name="dist-prepare"> + <available property="avalon.present" + classname="org.apache.avalon.blocks.Block" /> <mkdir dir="${tomcat.dist}"/> <mkdir dir="${tomcat.dist}/bin"/> <mkdir dir="${tomcat.dist}/conf"/> @@ -142,7 +146,73 @@ <!-- ====================== DIST: Clean Directory ======================= --> <target name="dist-clean"> <delete dir="${tomcat.dist}"/> + <delete dir="${tomcat.bar}"/> </target> + + <!-- ============= DIST: Create Avalon Block Distribution =============== --> + <!-- As soon as the "if" attribute bug of "target" is fixed in Ant, we --> + <!-- should add if="avalon.present" on the end of this target. --> + <target name="dist-opt-avalon" depends="all,dist"> <!--if="avalon.present"--> + <mkdir dir="${tomcat.bar}"/> + <mkdir dir="${tomcat.bar}/conf"/> + <mkdir dir="${tomcat.bar}/server"/> + <mkdir dir="${tomcat.bar}/tomcat-conf"/> + <mkdir dir="${tomcat.bar}/tomcat-lib"/> + <mkdir dir="${tomcat.bar}/webapps"/> + <mkdir dir="${tomcat.bar}/work"/> + <copy todir="${tomcat.bar}/conf"> + <fileset dir="catalina/src/conf" includes="${tomcat.version}.conf.xml"/> + </copy> + <copy todir="${tomcat.bar}/tomcat-conf"> + <fileset dir="${tomcat.build}/conf" includes="*" + excludes="avalon-server.xml,server.xml,avalon-MANIFEST.MF, + ${tomcat.version}.conf.xml"/> + </copy> + <copy file="catalina/src/conf/avalon-server.xml" + tofile="${tomcat.bar}/tomcat-conf/server.xml"/> + <copy todir="${tomcat.bar}/bin"> + <fileset dir="${tomcat.build}/bin"> + <include name="bootstrap.jar"/> + <include name="jndi.jar"/> + <include name="naming.jar"/> + <include name="servlet.jar"/> + </fileset> + </copy> + <copy todir="${tomcat.bar}/tomcat-lib"> + <fileset dir="${tomcat.build}/lib"> + <include name="jasper.jar"/> + <include name="namingfactory.jar"/> + </fileset> + </copy> + <copy todir="${tomcat.bar}/server"> + <fileset dir="${tomcat.build}/server"> + <include name="catalina.jar"/> + <include name="jakarta-regexp-1.2.jar"/> + <include name="warp.jar"/> + </fileset> + </copy> + <copy todir="${tomcat.bar}/webapps"> + <fileset dir="${webapps.build}" includes="**"/> + </copy> + <copy todir="${tomcat.bar}"> + <fileset dir="catalina/src/share"> + <include name="org/apache/catalina/startup/*.xinfo"/> + </fileset> + </copy> + <copy todir="${tomcat.bar}"> + <fileset dir="${catalina.build}/classes" includes="**/TomcatBlock.*"/> + </copy> + + <!-- Now we put everything in a jar that has a .bar file extention --> + <mkdir dir="${avalon.deploy}"/> + <jar jarfile="${avalon.deploy}/${tomcat.version}.bar" + manifest="catalina/src/conf/avalon-MANIFEST.MF"> + <fileset dir="${tomcat.bar}" includes="**"/> + </jar> + + <delete dir="${tomcat.bar}"/> + + </target> </project>
--- build.xml Fri Feb 9 14:56:29 2001 +++ build.xml-new Fri Feb 9 14:56:22 2001 @@ -8,7 +8,6 @@ <property name="catalina.dist" value="dist"/> <property name="servletapi.build" value="../../build/servletapi"/> - <property name="avalon.dist" value="../../dist/avalon"/> <!-- ================== Derived Property Values ========================= --> <property name="jaxp.jar" value="${catalina.jaxp.home}/jaxp.jar"/> @@ -107,7 +106,11 @@ unless="jdbcse.present" /> <exclude name="**/factory/TransactionFactory.java" unless="jta.present" /> - <exclude name="**/startup/CatalinaBlock.java" + <exclude name="**/startup/TomcatBlock.java" + unless="avalon.present" /> + <exclude name="**/valves/AvalonAccessLogValve.java" + unless="avalon.present" /> + <exclude name="**/logger/AvalonFileLogger.java" unless="avalon.present" /> </javac> @@ -262,24 +265,6 @@ </target> - <!-- ============= DIST: Create Avalon Block Distribution =============== --> - <!--FIXME : Can't get that to work ... Ant bug ?--> - <!--target name="dist-opt-avalon" depends="build-main" if="avalon-present"--> - <target name="dist-opt-avalon"> - <jar jarfile="${avalon.dist}/bin/blocks/catalina.bar"> - <fileset dir="${catalina.build}/classes"> - <include name="org/apache/catalina/startup/Bootstrap.class" /> - <include name="org/apache/catalina/startup/CatalinaBlock.class" /> - <include name="org/apache/catalina/loader/**" /> - </fileset> - <fileset dir="src"> - <include name="**/conf/catalina.conf.xml"/> - </fileset> - <fileset dir="src/share"> - <include name="**/startup/*.xinfo"/> - </fileset> - </jar> - </target> <!-- ======================== DIST: Clean Directory ===================== --> <target name="dist-clean">
--- 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))
--- 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);
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]