On May 28, 2010, at 3:22 PM, SunSeaAndPalms wrote:

> 
> Technologies that are used in my application requires classloader with
> 'addTransformer(ClassFileTransformer)' method and claims that Geronimo's 
> default org.apache.geronimo.kernel.config.MultiParentClassLoader , doesn't
> have it. So I need to setup my special class loader for my application
> (war). I use Geronimo with Tomcat. I was told that specifying classloader is
> a very simple process on Tomcat. Following example shows how to do it (The
> file is named "context.xml"):
> 
> <Context path="/myWebApp" docBase="/my/webApp/location">
>    <Loader
> 
> loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
> </Context>
> 
> The alternative for Geronimo is using "geronimo-tomcat.xml" in deployment
> plan (I read about it from 
> http://www.ibm.com/developerworks/java/library/os-ag-tomcat/ this doc ). The
> problem is that there isn't a classloader property specified.
> 
> So my question is: How can I change default classloader with a special one
> for my web application deployed on Geronimo?

You can't change what classloader geronimo uses for your web app.  However, you 
can register a ClassTransformer quite easily.  We do this for jpa.  Here's the 
code we use, from 2.2  
plugins/openjpa/geronimo-persistence-jpa10/src/main/java/org/apache/geronimo/persistence/PersistenceUnitGBean.java:

        public void addTransformer(ClassTransformer classTransformer) {
            TransformerWrapper transformer = new 
TransformerWrapper(classTransformer, classLoader);
            transformers.add(transformer);
            TransformerAgent.addTransformer(transformer);
        }


public class TransformerWrapper implements ClassFileTransformer {

    private final ClassTransformer classTransformer;
    private final ClassLoader classLoader;

    public TransformerWrapper(ClassTransformer classTransformer, ClassLoader 
classLoader) {
        this.classTransformer = classTransformer;
        this.classLoader = classLoader;
    }

    public byte[] transform(ClassLoader loader, String className, Class<?> 
classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) 
throws IllegalClassFormatException {
        if (loader != classLoader) {
            return null;
        }
        try {
            return classTransformer.transform(loader, className, 
classBeingRedefined,  protectionDomain, classfileBuffer);
        } catch (IllegalClassFormatException e) {
            throw e;
        } catch (RuntimeException e) {
            return null;
        }
    }
}


If you don't care whether all classes, not just the ones in your app, are fed 
to your ClassTransformer, you can leave out the TransformerWrapper.

This code should go in a gbean with priority PRIORITY_CLASSLOADER to make sure 
it is installed before other components are started and perhaps load your 
classes untransformed.  See the PersistenceUnitGBean for more details.

Hope this helps
david jencks


> 
> 
> -- 
> View this message in context: 
> http://apache-geronimo.328035.n3.nabble.com/How-to-specify-classloader-for-web-application-deployed-on-Geronimo-tp853251p853251.html
> Sent from the Users mailing list archive at Nabble.com.

Reply via email to