1
votes

I am using the WebSphere Liberty Profile server, version 8.5.5.3. I have an ear containing multiple wars. I deploy them all exploded (ear and the war's of the modules inside it as well).

When deploying it I get the following class cast exception:

java.lang.RuntimeException: javax.xml.bind.JAXBException: 
ClassCastException: attempting to cast bundleresource://67.fwk-1166858817/javax/xml/bind/JAXBContext.class 
to jar:file:/C:/ws/IBM/java_1.7_64/jre/lib/rt.jar!/javax/xml/bind/JAXBContext.class.
Please make sure that you are specifying the proper ClassLoader.

I figured that the problem is that my bundled jax-api and jaxb-impl jars are not loaded, so I added to the server.xml the parentLast class loading option:

<enterpriseApplication id="ear-app" location="C:/ws/ear/exploded/ear-app.ear" name="ear-app" >
    <classloader delegation="parentLast" commonLibraryRef="provided-jars" privateLibraryRef="shared-libs"/>
</enterpriseApplication>    

I added my jax-api and jax-impl jars to this folder

<library id="shared-libs">
    <fileset dir="${server.config.dir}/lib/global" include="*.jar"/>
</library>

However I still have the ClassCastException, it looks like it is still using the parentFirst classloading?

I found other jaxb ClassCastException threads, but not when using the Liberty profile..

2
Did you tried to remove those jars from your application to load only the server classes? - Gas
No I did not try that as we need the newer library versions instead of the ones provided by WebSphere. - tazzer
Liberty has jaxb-2.2. Which one do you need? Also what features you have enabled in server.xml? - Gas
Okay, I thought Liberty was on older one. I will remove the parentLast in my server.xml. I have the following features enabled: <feature>servlet-3.0</feature> <feature>wasJmsServer-1.0</feature> <feature>wasJmsClient-1.1</feature> <feature>jndi-1.0</feature> <feature>jdbc-4.0</feature> - tazzer

2 Answers

1
votes

Maybe it is a typo, but in your post you have delegation="parentFirst" instead of parentLast.

Did you check to just change delegation for application like this:

<enterpriseApplication id="ear-app" location="C:/ws/ear/exploded/ear-app.ear" name="ear-app" >
    <classloader delegation="parentLast"/>
</enterpriseApplication> 

For more details see Overriding a provided API with an alternative version

0
votes

I worked aroud the problem by not using the parentLast. Thanks for the help.