(original) (raw)
/* * This java source file is placed into the public domain. * * The orginal author is Ceki Gulcu, QOS.ch * * THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, NOT EVEN * THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR OF THIS SOFTWARE, * ASSUMES _NO_ RESPONSIBILITY FOR ANY CONSEQUENCE RESULTING FROM THE * USE, MODIFICATION, OR REDISTRIBUTION OF THIS SOFTWARE. */ package ch.qos.test; import ch.qos.ChildFirstClassLoader; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.net.URL; /** * This example demonstrates that in child-first trees, JCL will throw * an exception as soon as LogFactory is called after the TCCL is set * to a child class loader and when both the child and parent class * loaders have direct access to commons-logging.jar * * Usage: * * java -cp classes;lib/commons-logging.jar ch.qos.test.ChildFirstTestJCL0 * * @author Ceki Gülcü */ public class ChildFirstTestJCL0 { public static void main(String[] args) throws Exception { ChildFirstClassLoader child = new ChildFirstClassLoader( new URL[] { new URL("file:lib/commons-logging.jar") }); Thread.currentThread().setContextClassLoader(child); // JCL will throw an exception as soon as LogFactory is called after the // is TCCL set to a child class loader, and both the parent and child // have direct access to commons-logging.jar Log log = LogFactory.getLog("logger.name.not.important.here"); } }