tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Keith Yarbrough <kyar...@liaison.com>
Subject RE: What causes WebappClassLoader.addRepository() to be called?
Date Fri, 09 Nov 2001 18:51:22 GMT
Thanks Remy!

Upon your suggestion, I created an implementation of LifeCycleListener
(called ContextListener), and changed my context config in server.xml to add
the
	...
      <Listener className="com.foo.webservice.ContextListener" /> 
	...
tag.

The implementation of ContextListener is included below.

Additionally, I had to add a new context-param to my webapp WEB-INF/web.xml
file.

Like this,

		...
        <context-param> 
        	<param-name>code.base</param-name>
        	<param-value>http://mycompany.com/code/</param-value>
        </context-param>
		...


=======================================================================
package com.foo.webservice;

import java.util.StringTokenizer;

import org.apache.catalina.LifecycleListener;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.Loader;
import org.apache.catalina.Logger;

public class ContextListener implements LifecycleListener {

    private StandardContext context;

    public ContextListener() {
    }

    public void lifecycleEvent(LifecycleEvent event) {
        if (event.getType() == Lifecycle.START_EVENT) {
           context = (StandardContext)event.getLifecycle();
           start();
        }
    }

    public synchronized void start() {
        Loader loader = context.getLoader();
        String extCodeBase = context.findParameter("code.base");
        log("code.base = " + extCodeBase);

        if (extCodeBase != null) {
           StringTokenizer tokenizer = 
		  new StringTokenizer(extCodeBase, " ");
           while(tokenizer.hasMoreTokens()) {
               String url = tokenizer.nextToken();
               log("Adding URL " + url + " to WebappClassLoader path");
               loader.addRepository(url);
           }
        }
    }

    private void log(String message) {

        Logger logger = null;
        if (context != null)
            logger = context.getLogger();
        if (logger != null)
            logger.log("ContextConfig[" + context.getName() + "]: " +
message);
        else
            System.out.println("ContextConfig[" + context.getName() + "]: "
                               + message);

    }

}
=========================================================================



-----Original Message-----
From: Remy Maucherat [mailto:rmaucher1@home.com] 
Sent: Thursday, November 08, 2001 4:33 PM
To: Tomcat Developers List
Subject: Re: What causes WebappClassLoader.addRepository() to be called?

> I've been tracing through the code, and got lost trying to find what (if
> any) config setting can trigger a call to it.
> I need to add additional URLs (ex, http:/foo.com/classes/ ) to its search
> path.
>
> Any ideas would greatly appreciated.   I don't want to have to write my
own
> subclass of WebappClassLoader to accomplish this.
>
> But I'm almost to that point.

That functionality is used in embedded mode by the J2EE RI.
If you want to use it, it's quite easy to do by writing a lifecycle listener
(and call addRepository when you get the start event). There are a few
examples of lifecycle listeners in the Catalina source.

Remy


--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message