3
2
|
I had a problem with my application. To resume the problem, I had to do migrate an application from jboss 4 to jboss 5.
During the war deployement, I had this error:
After many searchs, I found this error was here because I had several time the same class in differents packages. Once in a dependency package (from my pom.xml) and once provided by jboss.
So, to resolve this problem, I have give a scope "provided" for my dependency.
But I don't understand why this solution works. I thought it works to have several time the same class in an application. I know it's not a good thing, but with jboss 4, it's work.
Someone can explain me why it works with jboss 4 and not with jboss 5.
Thanks for your explanation :)
| ||||
|
8
|
What you are seeing is the effect of an application server loading JBoss' libraries and EAR libraries in separate classloaders
You can think of an EAR's class loader hierarchy similar (but not necessarily) to :
Bootstrap ClassLoader -> System Class Loader -> JBoss System Class Loader -> Ear Class Loader -> War Class Loader.
Where war class loader's parent is the ear class loader and so forth.
Now if Bootstrap ClasssLoader has a jar A loaded and the ear is also being deployed with jar A, Bootstrap Class Lodaer and Ear Class Loader will have the same class created twice in separate class loaders.
I would assume (not 100% sure of this) that JBoss 4 didnt come bundled with javax/xml/namespace/QName. If that is true JBoss 5 is more then likely a different, upgraded, version of Java (4 -> 5 or 5 -> 6). As a result (with the new JBoss 5), when you try to pass javax/xml/namespace/QName into one of your classes, it is expecting the class from the ear. However you are giving it the QName class from the Bootstrap classloader because of the classloader preferences (parent first and so forth).
Since the class types are equal but the class instances are not equal you get a LinkageError
Edit:
Just two address the two comments -
The class loading behavior as jtahlborn noted is deffinitely different. In normal applications, the system classes like QName will be consistently looked for in the bootstrap classloader. In your error it looks as if javax/xml/datatype/DatatypeConstants is being loaded in org/jboss/classloader/spi/base/BaseClassLoader. Lets assume thats the EAR classloader (or WAR). A quick google shows that is part of the xml-apis' family and possibly jaxp-api.
So somewhere in your code (or another libraries code located in the EAR's class loader) needed DatatypeConstants - which forced the lookup of the class in the EAR's classloader. The creation of the QName object though loaded the class from the bootstrap classloader (instead of the EAR). This would happen if the QName class has already been initialized by the system, which it probably has.
This as you can imagine isn't suppose to happen. It actually looks like you have parent-last. Because when loading a class off the JBoss class loading mechanism, had parent-first been enabled, the initial DatatypeConstants would have returned the parent's (bootstrap) DatatypeConstants and not the childs. So as jtahlborn noted you would want the children's classloader here to be ignored.
As far as the resolution goes, unless you need the dependencies for a specific reason (like a slightly newer version is better then the current) I would delegate to the jboss's implementation. If thats not the case, you can take a look at the
class-loading java2ClassLoadingCompliance element that the jboss configuration has. | ||||||||||||||||||||
|
1
| -verbose:class in VM args will give how the Class is getting loaded. If there is duplicate you can remove the conflicting jar/jars. | |||
add comment |