|
|
|||||
|
|
|||||
|
|
Class.forName() is evil We've all done it before I guess. Called Class.forName( "com.foo.MyClass" ) to load some class at runtime based on some configurable class name. At first it seems very groovy. However this does not work very well in application servers, containers or various environments like Maven, Ant, JUnit etc. The days of everything being in the system class loader are over, now we need to live in a multiple-classloader world. Solution? Try use the current thread's context class loader or the class loader used to load your code. So try replace this... Class theClass = Class.forName( className ); with this more verbose version (which could easily be wrapped in a helper method) Class theClass = null;
While we're talking about living in multi-classloader worlds, bob's new project ClassWorlds looks very groovy. Update: thanks for the comment from Mark - the above code has been refactored to ensure that the class is initalized. |