package org.apache.catalina.loader; import java.io.File; import org.apache.catalina.LifecycleException; /** * User configurable web application class loader wrapper *

* This class subclasses the default catalina WebappLoader class * and adds the option to set a 'classpath' attribute to the <loader> * element of a context definition. *

* When such an attribute is filled with a list of paths (seperated by the system's * path seperator, for example- a colon), then thos paths will be added to the * classloader external repositories. *

* This utility should only be used for developing applications against constantly * changing 3rd party APIs, and should not be used for deployment on production * servers. * * License: GPL or LGPL or Apache License - take your pick * * @author Oded Arbel * @version $Revision$ $Date$ */ public class ConfigurableWebappClassLoader extends WebappLoader { private String m_classpath = null; /** * Support all the constructors offered by WebappLoader */ public ConfigurableWebappClassLoader() { super(); } /** * Support all the constructors offered by WebappLoader * @param parent parent class loader */ public ConfigurableWebappClassLoader(ClassLoader parent) { super(parent); } /** * support the bean property 'classpath' * @param classpath Class path to set */ public void setClasspath(String classpath) { m_classpath = classpath; } /** * Start the class loader and register my external classpath */ public void start() throws LifecycleException { addConfigurableRepositories(); super.start(); } private void addConfigurableRepositories() { if (m_classpath == null) return; String[] filepaths = m_classpath.split(File.pathSeparator); for (int i = 0; i < filepaths.length; i++) { if (!filepaths[i].endsWith(".jar") && !filepaths[i].endsWith("/")) filepaths[i] += "/"; addRepository("file:" + filepaths[i]); } } }