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
> >
> >
> >
>