Dominique Devienne wrote:
Sounds like the CL you create delegates to the Ant CL, thus your problem.Firstly, many thanks for your help with the DynamicConfigurator stuff. It worked a treat.
Create your own CL by making it delegate to the Root/Bootstrap CL (by
setting the parent loader to null), and the classes will always be loaded
from your classes (may duplicate-load the some classes Ant loaded in its CL,
but seems alright for you).
As to class loading, It is gradually getting worse. I've just realised that my IDE had included all of the Cocoon classes into the classpath for Ant, so all of Cocoon's classes were there all along! :-(
As soon as I remove these jars from Ant's classpath, it stops working at all. So I'm now pretty lost.
All I want to do is this:
In my Task, create a classloader that will ONLY load from Cocoon/WEB-INF/lib, and then run the following:
CocoonBean cocoon = new CocoonBean();
OutputStreamListener listener = new OutputStreamListener(System.out);
cocoon.addListener(listener);
BeanConfigurator.configure(xconf, cocoon, "", uriGroup, listener);
System.out.println(getProlog(Constants.NAME, Constants.VERSION, Constants.YEAR));
cocoon.initialize(); cocoon.process(); cocoon.dispose();
listener.complete(); return (listener.isSuccessful() ? 0 : 1);
All of the classes mentioned are from Cocoon, none from Ant. Then I'd switch my classloader back to the Ant one, and I'd be sorted.
Presumably this is a pretty straightforward requirement? Are you able to suggest places I can look for examples? I've tried looking at the Java class, but I quickly get out of my depth.
Do I need to load all of my classes using introspection, or can I refer to them by name as I have above? Do all includes for a class need to be available to the classloader that loads that class?
I'm no class loading expert, but at first glance this should work. --DDI've not even reached beginner level when it comes to class loading I'm afraid!
Thanks again,
Upayavira
-----Original Message----- From: Upayavira [mailto:[EMAIL PROTECTED] Sent: Thursday, October 09, 2003 2:39 PM To: [EMAIL PROTECTED] Subject: Preventing Parent Classloading
I'm working on a CocoonTask. Cocoon has a significant bundle of jars, some of which overlap with Ant's.
In my task, I set up a class loader responsible for loading Cocoon classes, which works, apart from when those same classes exist in Ant, when the Ant ones are loaded instead of Cocoon's.Ant has a different version of org.apache.log.Hierarchy which is incompatible with the one in Cocoon, and thus resulting in an IllegalAccessError.
To quote from the javadocs for ClassLoader:
"When requested to find a class or resource, a ClassLoader instance will delegate the search for the class or resource to its parent class loader before attempting to find the class or resource itself. "
How can I reverse this, so that the Cocoon ClassLoader is used in preference? Or prevent the delegation to the parent class loader?
Thanks in advance.
Regards, Upayavira
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]