Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 30505 invoked from network); 4 Oct 2004 19:22:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 4 Oct 2004 19:22:54 -0000 Received: (qmail 16665 invoked by uid 500); 4 Oct 2004 19:22:51 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 16617 invoked by uid 500); 4 Oct 2004 19:22:50 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 16596 invoked by uid 99); 4 Oct 2004 19:22:50 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from [66.7.245.130] (HELO ponder.azulix.com) (66.7.245.130) by apache.org (qpsmtpd/0.28) with ESMTP; Mon, 04 Oct 2004 12:22:48 -0700 Received: from localhost (localhost [127.0.0.1]) by ponder.azulix.com (Postfix) with ESMTP id A9D255003 for ; Mon, 4 Oct 2004 12:24:08 -0700 (PDT) Received: from ponder.azulix.com ([127.0.0.1]) by localhost (ponder [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 03320-01 for ; Mon, 4 Oct 2004 12:24:06 -0700 (PDT) Received: from [192.168.4.230] (unknown [192.168.5.1]) by ponder.azulix.com (Postfix) with ESMTP for ; Mon, 4 Oct 2004 12:24:06 -0700 (PDT) Message-ID: <4161A30D.90209@azulix.com> Date: Mon, 04 Oct 2004 12:22:53 -0700 From: Tim Meals User-Agent: Mozilla Thunderbird 0.8 (X11/20040913) X-Accept-Language: en-us, en MIME-Version: 1.0 To: dev@ant.apache.org Subject: Help with getMethod and AntClassLoader X-Enigmail-Version: 0.86.1.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at azulix.com X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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( getProject().getCoreLoader(), getProject(), classpath, true ); String result = g.generate( "SampleClass", true, cl ); } } If I run the Generator through BeanShell or via an Ant 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 task. Thanks to all who can help me see something I'm overlooking. Tim -- Tim Meals Senior Programmer --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org