ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "T Master" <tmas...@iknowledgeinc.com>
Subject Re: loading classes in a custom task
Date Wed, 15 Aug 2001 20:50:36 GMT
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" <tmaster@iknowledgeinc.com>
To: "ant user mailist" <ant-user@jakarta.apache.org>
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.
>
>
>


Mime
View raw message