-
1. Re: No ClassLoaders found for: ClassLoading problem in JMS M
avis1977 Jul 9, 2007 7:27 AM (in response to avis1977)Just forgot to mention
Jboss version is: 4.0.3SP1 -
2. Re: No ClassLoaders found for: ClassLoading problem in JMS M
adrian.brock Jul 9, 2007 8:05 AM (in response to avis1977)The behaviour is correct.
Class.forName() is a bad classloading api that shouldn't be used except
in the most trivial of environments.
You need to figure out why your generated class
is not visible from the context classloader (the classloader of the MDB).
Most likely because you've created your own classloader that is invisible
from the rest of the classloading system or something like this?
http://jira.jboss.org/jira/browse/JBAS-3691
i.e. you used a backdoor to defineClass() on a classloader
that never invokes findLoadedClass()
(like IBM started doing with their proxy generation). -
3. Re: No ClassLoaders found for: ClassLoading problem in JMS M
avis1977 Jul 12, 2007 10:00 AM (in response to avis1977)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;
} -
4. Re: No ClassLoaders found for: ClassLoading problem in JMS M
adrian.brock Jul 12, 2007 11:42 AM (in response to avis1977)"avis1977" wrote:
Thats correct... we are infact using the defineClass()
That's not surprising since there is no other way to load a class.
Is there a way still to make this class available to the RepositotyClass loader.
Yes. As long as you haven't already tried to load the class,
otherwise it will cache the miss and tell you forever the class could not be
loaded.
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.
That's not a JBoss classloader of any type. I can't even tell you whose it is
since you don't include the package name.
The other information doesn't make your question any more answerable than it was originally.
It's just some debug code for which you don't show any output or where
it is being executed.
Let me make some observations (I'm leaving this thread now).
1) THIS IS NOT A QUESTION ABOUT JMS - wrong forum
2) If you are going to play with classloaders then you need to understand how
they work.
In particular the JBoss classloading structure, i.e. what is visible from what context
e.g. each ejb gets its own thread context classloader (even if they share
the same underlying parent classloader)
3) What you are doing won't even work if you enable the java security manager.
4) If you really want your question answered (when you post it in a forum
that is relevant) then you need to post pertinent information.
e.g. I've yet to see the code that actually defines the class, where that is done
against which classloader, etc.
When I say which classloader, I mean classloader.toString() and
a print of the classloader.getParent() stack, NOT some code doingThread.currentThread.getContextClassLoader()
which it meaningless since it could have any value depending upon where your code executes.
The list of what is required for somebody to understand your question
is longer than this, you can find it on the WIKI.
I'm certainly not going to go through 20 posts to try to squeeze that information out of you. -
5. Re: No ClassLoaders found for: ClassLoading problem in JMS M
pbhatanglikar Oct 14, 2008 3:51 AM (in response to avis1977)I am also facing the same problem.
Hey avis , you got the solution??
Please share with us..
Thanks,
Prat