How to use JAX-WS 2.2.6 with JDK 1.6


JDK 1.6 comes with spec + implementation of JAX-WS 2.1. If we add all libs of JAX-WS 2.2.6 in our project classpath, the JDK still prefers it own JAXWS API i.e. version 2.1. It will cause jar conflicts or MethodNotFoundError etc.

To use JAX-WS 2.2.6 or later with JDK 1.6, we must force JDK to load spec+impl ver. 2.2.6. It is done by endorsing new library. There are two ways to endorse JDK to use our provided libraries instead of its own.

  1. From JAX-WS 2.2.6 downloaded bundle. Put only jaxws-api.jar and jaxb-api.jar to JDK1.6/jre/lib/endorsed directory.
  2. Set "java.endorsed.dirs" environment variable, it should point to directory than must contain jars to be endorsed. e.g. java.endorsed.dirs=d:\endorsedlibs, where endorsedlibs directory contains two jar files mentioned in step 1. 

We must not put all JAX-WS 2.2.6 jar files into endorsed directory. Only specifying two API jars (the specification) is enough. At runtime, the right implementation would be loaded from your project class path. Also note that, we don't need to put jaxws-api.jar and jaxb-api.jar into your project classpath. As it will cause duplication of jar.

Another important point is, the JAX-WS 2.2.6 used JAXB 2.2. If an older JAXB is found in your classpath, it will cause issues (JDK 6 comes with JAXB 2.0). Make sure there is no copy of jaxb-api.jar older than version 2.2. In my case, our webservice module was dependent on 'core' module, which was using jaxb-api.jar version 2.1, it wasted much time to identify the issues.

Comments

  1. This did not work for me. I tried the first option. Second option does not work on linux as the variable name contains ".". I also tried passing -Djava.endorsed.dirs but did not work. Same thing I tried on windows also but it fails. I am using JDK1.6_34. At run time I get this error -

    Caused by: java.lang.NoSuchMethodError: javax.xml.ws.WebFault.messageName()Ljava/lang/String;
    at com.sun.xml.ws.model.RuntimeModeler.processExceptions(RuntimeModeler.java:1252)
    at com.sun.xml.ws.model.RuntimeModeler.processDocBareMethod(RuntimeModeler.java:1422)
    at com.sun.xml.ws.model.RuntimeModeler.processMethod(RuntimeModeler.java:744)
    at com.sun.xml.ws.model.RuntimeModeler.processClass(RuntimeModeler.java:506)
    at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:337)
    at com.sun.xml.ws.db.DatabindingImpl.(DatabindingImpl.java:102)
    at com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:75)
    at com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:59)
    at com.sun.xml.ws.db.DatabindingFactoryImpl.createRuntime(DatabindingFactoryImpl.java:128)
    at com.sun.xml.ws.client.WSServiceDelegate.buildRuntimeModel(WSServiceDelegate.java:803)
    at com.sun.xml.ws.client.WSServiceDelegate.createSEIPortInfo(WSServiceDelegate.java:810)
    at com.sun.xml.ws.client.WSServiceDelegate.addSEI(WSServiceDelegate.java:786)
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:407)
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:384)
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:366)
    at javax.xml.ws.Service.getPort(Service.java:92)

    ReplyDelete
    Replies
    1. NoSuchMethodError is stating that javax.xml.ws.WebFault.messageName does not exist. This implies that you are still running a client that has been created on Jax-ws 2.1 RI or is a server set to JAX-Ws 2.1 (i.e. running default Java 6) attempting to run a JAX-WS 2.2 RI client code.

      When you've downloaded JAX-WS 2.2 (to run with Java 1.6), have a look at the bin directory and the scripts in there. You will see JAX-WS 2.2 related wsgen and wsimport. These are the ones that need to be used instead of the JDK1.6 default wsgen and wsimports.

      Delete

Post a Comment