I've defined a class that should call a well-known method inside of a dynamically-loaded class. Here's a short snippet of sample code:
public class Generator
{
public String generate( String className, boolean flag, ClassLoader cl )
throws Exception
{
Puck p = new Puck(); // this gets passed around to other classes as an
// object they can write common data to
Class[] parameters = { p.getClass(), boolean.class };
Object[] arguments = { p, new Boolean( true ) };
Class c = Class.forName( className, true, cl ); Method generateMe = c.getMethod( "generate", parameters ); generateMe.invoke( null, p, flag );
return p.toString(); } }
public class SampleClass
{
public static void generate( Puck p, boolean flag )
{
// recursively call generate on other classes, using code similar to above ...
Method m = c.getMethod( "generate", parameters );
m.invoke( null, p, flag );
}
}
public class GenerateAntTask extends MatchingTask { private Path classpath;
// all of the MatchingTask attributes and stuff are up here ...
public void execute() throws BuildException { Generator g = new Generator(); AntClassLoader cl = new AntClassLoader( getProject().getCoreLoader(), getProject(), classpath, true ); String result = g.generate( "SampleClass", true, cl ); } }
If I run the Generator through BeanShell or via an Ant <java> task (with a main method, of course), it works fine. If I try running my custom task, I get a NoSuchMethodException when trying to call getMethod. I'm guessing it's the AntClassLoader, because that's the only variant between the tests, but AntClassLoader is used by ExecuteJava.java to perform the <java> task.
Thanks to all who can help me see something I'm overlooking.
Tim
--
Tim Meals Senior Programmer
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]