ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Meals <>
Subject Help with getMethod and AntClassLoader
Date Mon, 04 Oct 2004 19:22:53 GMT
I'm having some difficulty figuring out why the AntClassLoader isn't 
finding a public void static method with the parameters I'm asking for.  
My environment is Linux 2.6.8, Sun JDK 1.4.2 and Ant 1.6.2.

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(
          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 to 
perform the <java> task.

Thanks to all who can help me see something I'm overlooking.


Tim Meals 	
Senior Programmer

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message