[kepler-dev] Dynamically adding classes to the classpath

Dan Higgins higgins at nceas.ucsb.edu
Tue Sep 18 12:23:01 PDT 2007

Hi All,

    As anyone who has worked with Kepler has probably noticed, Kepler 
has an incredibly long classpath! (due to all the addtional jars used by 
the collection of actors that have been added to the system). In 
particular, there are about 100 jars in the $KEPLER/lib/jar/ directory 
that have to be included. Ant or Eclipse or some shell script needs to 
create a list of these for the classpath variable and pass this to the 
java command line launching Kepler. it would be nice to  just 
automatically include all the jar files needed.

    Well, it turns out that there is a way to dynamically add files to 
the classpath from within a Java program. See


for a class called 'ClassPathHacker'. I have added this class to Kepler 
and added some code to the Kepler startup class (KeplerApplication) to 
automatically add all files under $KEPLER/lib/jar/ to the classpath as 
the first thing done when Kepler starts up. I also removed the files in 
this location from the classpath generated by ant. Please let me know if 
this causes problems for anyone.

    Besides cleaning up the command window when Kepler starts, this 
change means that addition of actors to Kepler will only require someone 
to drop a jar into the jar directory! It will also be possible to 
include java code in a KAR file (as a jar) and we can modify the KAR 
loader to copy the jar to this directory and add it to the classpath at 
the same time. [Note that this approach does not create a new 
ClassLoader, so we won't get the ability to have several versions of a 
class or unload it. However, we will be able to load java based actors 
from the Repository.]


Dan Higgins                                  higgins at nceas.ucsb.edu
http://www.nceas.ucsb.edu/    Ph: 805-893-5127
National Center for Ecological Analysis and Synthesis (NCEAS) Marine Science Building - Room 3405
Santa Barbara, CA 93195

More information about the Kepler-dev mailing list