imesh
imesh

Reputation: 123

java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to com.sun.xml.bind.api.JAXBRIContext

I created a jaxws web service. I totally followed the url

The service was up perfectly without any error. But the server having errors when request hit it.

SEVERE: caught throwable
java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to com.sun.xml.bind.api.JAXBRIContext
    at com.sun.xml.ws.db.glassfish.JAXBRIContextFactory.newContext(JAXBRIContextFactory.java:74)
    at com.sun.xml.ws.spi.db.BindingContextFactory.create(BindingContextFactory.java:149)
    at com.sun.xml.ws.message.jaxb.JAXBMessage.create(JAXBMessage.java:160)
    at com.sun.xml.ws.fault.SOAPFaultBuilder.createSOAP11Fault(SOAPFaultBuilder.java:433)
    at com.sun.xml.ws.fault.SOAPFaultBuilder.createSOAPFaultMessage(SOAPFaultBuilder.java:210)

I checked through out stackoverflow and many other sites all says jar file conflict.
I use java-6-openjdk.
and below is my jar file list in the jetty server.

gmbal-api-only.jar
ha-api.jar
jaxb-core.jar
jaxb-impl.jar
jaxws-rt.jar
management-api.jar
policy-2.3.1.jar
stax-ex.jar
streambuffer-1.5.1.jar

Since above jars are not working I tried with
Go here
Download JAX-WS RI distribution.

But those jars gave the same error.

Upvotes: 3

Views: 29482

Answers (3)

Same error occured on my Java 7 project. Removing com/sun/xml/bind/jaxb-impl-2.2.6.jar com/sun/xml/bind/jaxb-xjc-2.2.6.jar

dependencies solved the problem.

Alternative solution :

clientPort is an Interface with @WebService annotation.

    BindingProvider prov = (BindingProvider) clientPort;        
    prov.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);
    prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, serviceUsername);
    prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, servicePassword);

Upvotes: 1

Anupam Pawar
Anupam Pawar

Reputation: 231

I have also came across same exception and little bit googling it confirmed that its because of classpath/jar issue.

I'm using Java 6.0 as build and runtime environment and my project setup having jaxb-api.jar and jaxb-impl.jar. I simply removed these two jars from classpath and it works.

As if we are having Java 6.0 we dont need to use explicitely JAX binding jars. It comes by default with Java 6.0.

Upvotes: 3

Xargos
Xargos

Reputation: 643

Check this thread: web client for web service. The main problem I think is that you have several jaxb jars that differ in versions. For example, I think that jaxb is already part of jaxws-rt.jar which would mean you don't need jaxb-core.jar and jaxb-impl.jar.

Upvotes: 1

Related Questions