Could you, please, help with the following issue?
When generate WS client code (with wsimport ant task), all classes are generated automatically in the same package (e.g. helloservice.endpoint) as web service, e.g. if my web-service has method
public Node getNode();
so class helloservice.endpoint.Node is generated. Nevertheless, I have my own helloservice.Node class that I want to use in web-service.
I defined bind.xml file :
<bindings version="2.0" xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" >
<bindings node="wsdl:definitions/wsdl:portType[@name='Node']">
<class name="helloservice.Node"/>
</bindings>
</bindings>
and pass it to wsimport task as binding parameter, but get the error :
[wsimport] [ERROR] XPath evaluation of "wsdl:definitions/wsdl:portType[@name='Node']" results in empty target node [wsimport] line 2 of file:/C:/work/projects/svn.ct/trunk/jwstutorial20/examples/jaxws/simpleclient/bind.xml
Could anybody, please, recommend what is wrong here? Can I use my own classes in generated web-service classes in such way, or I need smth more complicated?
Thanks in advance.
To generate classes from wsdl, use in ant :
<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
<wsimport keep="true" sourcedestdir="..." wsdl="..." wsdllocation="..." xnocompile="true" />
Don't use 'package' attribute on wsimport ant task, so all classes are created in their correct packages.
In general, to customize package, i.e. change generated package name a.b.c to name x.y.z add element to wsimport task and define binding.jxb file as follows.
<jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings schemaLocation="schema-for-a.b.c.xsd" node="/xs:schema">
<jxb:schemaBindings>
<jxb:package name="x.y.z" />
</jxb:schemaBindings>
</jxb:bindings>
</jxb:bindings>
where schema-for-a.b.c.xsd is the schema generated by wsgen task (that creates wsdl with suitable schemes).
More detailed about JAXB customization : http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.6/tutorial/doc/JavaWSTutorial.pdf, section "Customizing JAXB Bindings"
来源:https://stackoverflow.com/questions/2960267/need-to-use-custom-classes-instead-of-generated-by-wsimport-in-web-services