You can't change a classloaders classpath. The only time you can set a classpath is when you create an instance of a classloader. In your application, you can create instances of URLClassloader and supply it with your classpath list.
There is a an Apache utility that does this, called AvalonRepository. You can download it from
www.apache.org. The avalon project is not documented very well, and it has a lot of sub projects. The people I know who use avalon, didn't learn how to use avalon from the docs at the avalon site. Rather they tend to learn by doing. Thats how I learned how to use it. I had to work on a project that had a Turbine servlet in it. The Turbine servlet uses avalon.
Avalon is much larger than the repository. This is just one small item, but it is broken out into its own jars and sub project.
To use it, you place your common jar files into a directory that functions as the repository. You then create these property files that end with .meta and place them into the repository. You create an instance of the InitialContext class that requires a path to the repository.
You use the context to request "Artifacts" from the repository. The name of the artifact corresponds to a .meta file. It reads the .meta file, creates the classloader and loads the jars listed in the .meta file.
There are code examples that you should be able to follow. However there is one very important item not documented. When you download the repository jars, do not place all of them into the application's class path. Only put the avalon-repository-main in the application's classpath. The other jars go into the repository. The main jar is a boot jar. It loads the others from the repository.
If anyone is interested in using the avalon repository and has any questions just post them.
[ June 24, 2004: Message edited by: Jim Hicks ]