I thinkI found it in task RMIC:
Path classpath = getCompileClasspath(baseDir);
loader = new AntClassLoader(project, classpath);
try {
String classname = ....
Class testClass = loader.loadClass(classname);
// One cannot RMIC an interface
if (testClass.isInterface() ||
!isValidRmiRemote(testClass)) {
return null;
}
} catch (ClassNotFoundException e) {
log("Unable to verify class " + classname +
". It could not be found.", Project.MSG_WARN);
} catch (NoClassDefFoundError e) {
log("Unable to verify class " + classname +
". It is not defined.", Project.MSG_WARN);
}
----- Original Message -----
From: "T Master" <[EMAIL PROTECTED]>
To: "ant user mailist" <[EMAIL PROTECTED]>
Sent: Wednesday, August 15, 2001 2:46 PM
Subject: loading classes in a custom task
> Given a fileset of *.jar is passed to a custom task, how can MyTask load
> the classes it requires? I have a classpath attribute that is a fileset.
> I've passed this to my task. As this is a collection of jar files, what
now
> must be done to load the class? Code snippet appreciated.
>
> e.g.
>
> public class MyTask
> {
> Path classpath = null;
>
> /**
> * Set the classpath to be used for this compilation.
> */
> public void setClasspath(Path aClasspath) {
> if (this.classpath == null) {
> this.classpath = aClasspath;
> } else {
> this.classpath.append(aClasspath);
> }
> }
>
> /**
> * Set the classpath to be used for this compilation.
> */
> public void addClasspath(Path aClasspath) {
> if (this.classpath == null) {
> this.classpath = aClasspath;
> } else {
> this.classpath.append(aClasspath);
> }
> }
>
> /**
> * Creates a nested classpath element.
> */
> public Path createClasspath() {
> if (classpath == null) {
> classpath = new Path(project);
> }
> return classpath.createPath();
> }
>
> /**
> * Adds a reference to a CLASSPATH defined elsewhere.
> */
> public void setClasspathRef(Reference r) {
> createClasspath().setRefid(r);
> }
>
> public void execute() throws BuildException() {
> .
> .
> .
>
> // need to load class javancss.Javancss as it is not in our system
> classpath.
> javancss.Javancss ncss = new javancss.Javancss( cmdArgs,
> Main.S_RCS_HEADER);
> }
> }
>
> T Master.
>
>
>