Over a million developers have joined DZone.

Generating a JAX-WS Webservice Client JAR From a WSDL

This article highlights some hidden and important configuration steps for creating a WS client JAR file.

· Java Zone

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

It seems generating a JAR file to consume a JAX-WS Webservice is fairly easy. But if you don't pay attention to the following points, it may suddenly become a nightmare for you.

So in this article, I will try to highlight some hidden and important configuration steps for creating a WS client JAR file.

  • First things first, you should pay attention to which Java version (Java 6, Java 7, or Java 8) you are using for your project. If your Java project depends on Java 6, and if you then create a client with Java 7 or Java 8, then you will get an UnsupportedClassVersionError error.

  • Create a temporary directory: (/home/ahmet/tmp).

  • Create a directory named target in tmp folder: (/home/ahmet/tmp/target).

  • Save your wsdl to the tmp directory: (/home/ahmet/temp/service.wsdl).

  • Edit your wsdl file and change the URLs from real Webservice addresses to localhost, then save and close the wsdl file.

  • Create a directory named META-INF in tmp folder: (/home/ahmet/tmp/target/META-INF).

  • Put your wsdl in the META-INF folder also: (/home/ahmet/tmp/target/META-INF/service.wsdl).

  • Create a file called jax-ws-catalog.xml with the following content:

<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
   <system systemId="http://localhost/wsdl/service.wsdl"uri="service.wsdl"/>
</catalog>
  • Also, put this file to META-INF folder: (/home/ahmet/tmp/target/META-INF/jax-ws-catalog.xml).

  • Create a file called Jaxb-bindings.xml with the following content: 

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:version="2.1">
    <jaxb:globalBindings>
        <xjc:serializable uid="1"/>
    </jaxb:globalBindings>
</jaxb:bindings>
  • Put this file to tmp folder (/home/ahmet/tmp/Jaxb-bindings.xml).

  • Please be sure that your operationg system locale is not in Turkish. wsimport capitalizes the lowercase characters at some points that cause some weird characters in code.

  • Be sure that you are in the tmp folder and run the following command (/home/ahmet/tmp):

wsimport -d target -keep -p PACKAGENAME -b Jaxb-bindings.xml -wsdllocation http://localhost/wsdl/service.wsdl -catalog jax-ws-catalog.xml service.wsdl


  • Change your working directory to target (/home/ahmet/tmp/target) and run the following command:

jar cvf service.jar .
  • Your Jar file is ready to use :)

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:
java ,jax-ws ,webservice

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}