[kepler-dev] Dynamically adding classes to the classpath

Edward A. Lee eal at eecs.berkeley.edu
Wed Sep 19 13:36:29 PDT 2007

Adding dynamically to the classpath would be a useful addition
to our "Instantiate Entity" mechanism in Ptolemy II...
Then you could instantiate an entity that is out of the standard
classpath...  Further, perhaps the additions to the classpath could
be stored with a model in an attribute.  This would make it much
easier to create models using proprietary libraries that are outside
the standard classpaths...  Also, it would become less necessary
for Kepler to have such a long classpath...


At 12:23 PM 9/18/2007, Dan Higgins wrote:
>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
> http://forum.java.sun.com/thread.jspa?threadID=300557&start=0&tstart=0
>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
>Kepler-dev mailing list
>Kepler-dev at ecoinformatics.org

Edward A. Lee
Chair of EECS and Robert S. Pepper Distinguished Professor
231 Cory Hall, UC Berkeley, Berkeley, CA 94720-1770
phone: 510-642-0253, fax: 510-642-2845
eal at eecs.Berkeley.EDU, http://ptolemy.eecs.berkeley.edu/~eal  

More information about the Kepler-dev mailing list