If you look at the source of ClassUtils, you will see how it tries to load the classes: http://grepcode.com/file/repo1.maven.org/maven2/org.apache.shiro/shiro-core/1.0.0-incubating/org/apache/shiro/util/ClassUtils.java#ClassUtils.forName%28java.lang.String%29
The first thing it tries is to load the class with the help of the ClassLoader attached to the thread. If it fails, it tries to load with the ClassLoader that loaded ClassUtils. If it fails, it tries to load the class with the system ClassLoader.
You can trick the first one, the thread context classloader. I must mention that this is only a workaround, not a solution that is nice in the OSGi world:
BundleWiring bundleWiring = context.getBundle().adapt(BundleWiring.class);
ClassLoader bundleClassLoader = bundleWiring.getClassLoader();
Thread currentThread = Thread.currentThread();
ClassLoader originalCl = currentThread.getContextClassLoader()
currentThread.setContectClassLoader(bundleClassLoader);
try {
System.err.println("Shiro : " + ClassUtils.forName("com.firm.demo.MyCustomClass"));
} finally {
currentThread.setContextClassLoader(originalCl);
}