cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Upayavira>
Subject Re: Ant Class Loading & CocoonTask
Date Thu, 09 Oct 2003 19:45:19 GMT
Stefano Mazzocchi wrote:

> On Thursday, Oct 9, 2003, at 14:19 Europe/Rome, Upayavira wrote:
>> I have written a Cocoon Ant task, which is really neat, and, as Marc 
>> was suggesting, it shares its config code with the CLI.
>> However, I'm having some classloading problems with it. I set up an 
>> AntClassLoader which points only to WEB-INF/lib, and it successfully 
>> loads in CocoonBean and associated classes. When it gets into the 
>> initialisation phase, however, it gets a Logger from Ant's copy of 
>> Velocity, rather than from a Cocoon jar.
>> How can I force the class loader to ignore Ant's classpath and just 
>> use Cocoon's for everything?
> Did you try forcing the classloader in the task' thread context? you 
> can basically ask the current classloader, wrap it with yours and set 
> that one in (this is what the ParanoidCocoonServlet does, BTW, Sylvain 
> was also able to get classes directly from Eclipse without the need 
> redeploy)
> that might trigger security exceptions in protected environments, but 
> ant is never used under a security manager (AFAIK). 

Below is the relevant code snippet (note the consciously hard coded 
path!). I just create an AntClassLoader and off I go. But it tries to 
load org.apache.log.Hierarchy from Ant's copy of Velocity, rather than 
our own library. The         loader.setThreadContextLoader() does force 
the classloader in the task's thread context, I think. But it is still 
getting me a class from Ant. The AntClassLoader does wrap the thread 
class loader, as I think you're saying.

I tried extending the AntClassLoader and copying the 
paranoidclassloader's loadClass method across into my subclass, but my 
loadClass method was never called.

Any ideas? This is frustrating because I think I'm sooooo close...

        AntClassLoader loader = null;
        Project project = getProject();
        Path path = new Path(project);
        FileSet classes = new FileSet();
        classes.setDir(new File("d:/documents/cocoon/cocoon 
        FileSet fileSet = new FileSet();

        loader = new AntClassLoader(project.getCoreLoader(), project,
                                                    path, false);
//loader.setParent(null); uncommenting this makes no difference
        try {
            CocoonBean cocoon = new CocoonBean();
            OutputStreamListener listener = new 
            BeanConfigurator.configure(xconf, cocoon, "", uriGroup, 

Constants.VERSION, Constants.YEAR));


            int exitCode = (listener.isSuccessful() ? 0 : 1);
        } catch (Exception e){
            System.out.println("Exception: "+e.getMessage());

Regards, Upayavira

View raw message