Friday, December 18, 2009
How can I manage my Java program's classpath?
I ran into an interesting article that shows a solution to the problem of running incompatible classes within a single JVM. The idea is to keep the launching application's classpath small and clean and then use a custom classloader to load the application's various pieces. Using separate classloaders is exactly how most Java EE containers keep applications from seeing each other's classes. I think this technique, couple with a command socket is a great way to launch an application. It is very possible to use multiple loaders to run variants of the same application within the JVM and not have to rely on OSGi or Java EE and the associated complexity. The technique is fairly simple to implement and helps to avoid those pesky ClassNotFound exceptions.