[jboss-user] [Messaging, JMS & JBossMQ] - Re: No ClassLoaders found for: ClassLoading problem in JMS M
avis1977
do-not-reply at jboss.com
Thu Jul 12 10:00:53 EDT 2007
Thats correct... we are infact using the defineClass()
Is there a way still to make this class available to the RepositotyClass loader.
By the way the classLoader instance that I get at the point of time when I generate my code is an instance of the GenericClassLoader.
Are there any other alternatives cos all we have is bytes[] of the class file at the time when we load these classes in memory.
Earlier my code called defineClass on the currentClass.class.getClassLoader()
I have changed the implementation to use the Thread.currentThread().getContextClassLoader().
No luck here... I get the NoClassLoaders found for error in the first Try Catch.
Here is how the code looks like now
private Class createClass(ClassWriter writer, String className,
String baseClassName) throws Exception {
Class clazz = null;
String qualifiedClassName = className.replaceAll("/", ".");
try {
clazz = Thread.currentThread().getContextClassLoader().loadClass(
qualifiedClassName);
} catch (Exception e) {
Class c = Class.forName("java.lang.ClassLoader");
Class[] args = new Class[] { String.class, byte[].class, int.class,
int.class };
java.lang.reflect.Method method = c.getDeclaredMethod(
"defineClass", args);
Object[] params = new Object[] { qualifiedClassName,
writer.toByteArray(), new Integer(0),
new Integer(writer.toByteArray().length) };
ClassLoader loader = Thread.currentThread().getContextClassLoader();
method.setAccessible(true);
clazz = (Class) method.invoke(loader, params);
method = c.getDeclaredMethod("resolveClass",
new Class[] { Class.class });
method.setAccessible(true);
method.invoke(loader, new Object[] { clazz });
}
return clazz;
}
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4063498#4063498
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4063498
More information about the jboss-user
mailing list