I am using wsimport to generate client stubs for JAX-WS webservice calls
wsimport
has the -p
option which allows to customise name of package.
For eg. if the WSDL has namespace of com.abc, then you can subsitute com.abc by com.pqr by calling wsimport
with the -p com.pqr
command line.
However, this works fine only if there is only one namespace used in the wsdl.
If there are multiple namespaces in the wsdl, is there a way to replace each of them with a different package name.
For eg. if I want namespace com.abc.s1 to be replaced by namespace com.pqr.s1 & namespace com.abc.s2 to be replaced by namespace com.pqr.s2.
If I use wsimport -p com.pqr.s1
, it puts all the generated classes into com.pqr.s1
Is there a way to achieve what I want?
Generally, you use a jax-b bindings file to customize the unmarshal process for a given XSD or WSDL. The bindings language provides the <package/>
directive for the purpose of customizing the generated package of a schema.
Given separate schemata, in separate files, you can have a composite bindings file that'll look something like this:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.0">
<jaxb:bindings schemaLocation="Flight.xsd" node="/xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="travel.flight"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="Hotel.xsd" node="/xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="travel.hotel"/>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
Where schemaLocation
will refer to the location of individual schema files, node
refers to the XML element that the binding declaration is supposed to apply to. <jaxb:package/>
will define the name of the output package.
You should then feed the bindings file to wsimport using the -b
directive and you should be fine
Reference: