ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jacques Bergeron" <jacques.berge...@dogico.com>
Subject RE: Dynamic load of Ant [EXPIRED TRIAL LICENCE]
Date Thu, 15 Jun 2000 08:13:36 GMT
Hi Kevin, all

Works fine!

Thanks a lot. I will correct the guys at Java Developper Connection that
said URLClassLoader does not support file: protocol. You know better!

Regards,

Jacques

-----Message d'origine-----
De : Kevin Regan [mailto:kevinr@valicert.com]
Envoyé : 14 juin, 2000 23:13
À : ant-dev@jakarta.apache.org
Objet : Re: Dynamic load of Ant [EXPIRED TRIAL LICENCE]

What I've been doing:

     private Class getClassFromClasspath( String classname,
                                                 String classpath )
         throws EventException, ClassNotFoundException {

         URL[] urls = parseClasspath( classpath );

         URLClassLoader loader = new URLClassLoader( urls );

         return loader.loadClass( classname );

    } // getClassFromClasspath


    private URL[] parseClasspath( String classpath )
        throws EventException {

        List urls = new ArrayList();

        StringTokenizer tokenizer =
            new StringTokenizer( classpath, CLASSPATH_SEPARATOR );

        while ( tokenizer.hasMoreTokens() ) {
            String filename = tokenizer.nextToken();

            File file = new File( filename );

            try {
                urls.add( file.toURL() );
            }
            catch ( MalformedURLException e ) {
                throw new EventException( "invalid filename: \"" +
filename +
                                          "\"" );
            }
        }

        if ( urls.size() == 0 ) {
            throw new EventException( "no paths found in \"" + classpath +
                                      "\"" );
        }

        return ( URL[] ) urls.toArray( new URL[ urls.size() ] );

    } // parseClasspath



On Wed, 14 Jun 2000, Kevin Regan wrote:

>
> Hmm, I've been usingthe URLClassLoader with files for a long
> time now.  Try it...
>
> --Kevin
>
>
>
> On Wed, 14 Jun 2000, Jacques Bergeron wrote:
>
> > Hi everyone,
> >
> > I am trying to run Ant directly from a Java program without having
> prior
> > knowledge of Ant`s directory (cannot intialize classpath on program
> > startup).
> >
> > I would need to dynamically change the CLASSPATH once I know Ant`s
> > directory
> > (choosen by the user). Since changing the classpath is not possible
> (so
> > was
> > I told) I would need to make a custom ClassLoader!?
> >
> > 1- Is it true that the classpath cannot be changed dynamically?
> >
> > 2- If so do you know any exemple of a custom ClassLoader that I could
> > use (I
> > was told that Java`s URLClassLoader did not support the file:
> protocol).
> > So
> > I`m searching for a model.
> >
> > Any help would be welcome :)
> >
> >
> >
> > Jacques
> >
> >
> >
>



Mime
View raw message