Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Generating a JAX-WS Webservice Client JAR From a WSDL

DZone's Guide to

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
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

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 :)

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

Topics:
java ,jax-ws ,webservice

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}