This content has been marked as final. Show 5 replies
Not really. If you want two different copies of the same class in your JVM (so you can keep their static variables separated and so on) then you will have to have them loaded by two different classloaders. If you try to have them both loaded by the system classloader then there aren't any shenanigans you can pull to make them appear different.1 person found this helpful
Can I create multiple instances of the system classloader and use those separate instances to create my separate apps? I wouldn't want to write a custom ClassLoader that does the same job of reading classes from JAR files.
you don't need to write your own classloader. for most purposes, URLClassLoader is sufficient.
The class loader delegation model is such that even if you write your own class loader, its parent, presumably the system class loader, will be allowed first to try to load the class.
Therefore, your classes should not be on the classpath!
If the above is not a problem for you, use instances of URLClassLoader, which allow you to specify the file or jar locations of the classes as URL's. Jar URL's look like this: "jar://...".
Edited by: baftos on Sep 30, 2010 2:35 PM
Thank you, all. That last tip potentially saved me some time troubleshooting.