This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
URLClassLoader.newInstance
Posted by Kevin Welker on 15 Mar 1999, 3:17 PM
I am trying to dynamically load classes from JAR files using the JDK 1.2 class URLClassLoader in an Applet without adding the policy to create class loaders. This doesn't quite seem like it should be possible, but I am able to do so by "getting" a URLClassLoader by calling the static method: URLClassLoader.newInstance(URL[] urls, ClassLoader parent). My first question is, how is this working without setting a policy? Next, I am having a slight performance problem with this technique. I was hoping that by specifying a URL for a JAR file, that loading my first class from the JAR file would also load the other classes from the JAR file. I think I see why that was not done, but the resulting problem is that when my class is getting resolved, the other dependent classes in the JAR file must be loaded. This is resulting in hits back to the web server for each class to see if each can be found in the CLASSPATH. This seems to be eating up much of the efficiency I was hoping to obtain by putting the classes in a JAR file to begin with. Do you see a way around this? Thanks in advance for any help. -- Kevin Welker
Replies:
|