开始命令用的: wsdl2java -d src-cxf -b custom.xml -exsh true -encoding utf-8 -autoNameResolution -verbose xxxxx.wsdl
生成的Service.java文件是这样的:
@WebServiceClient(name = "abcWebServices", wsdlLocation = "file:xxxxx.wsdl", targetNamespace = "http://xml.abc.com") public class abcWebServices extends Service {
public final static URL WSDL_LOCATION;
public final static QName SERVICE = new QName("http://xml.abc.com", "abcWebServices"); public final static QName abcWebServicesPort = new QName("http://xml.abc.com", "abcWebServicesPort"); static { URL url = null; try { url = new URL("file:xxxxx.wsdl"); } catch (MalformedURLException e) { java.util.logging.Logger.getLogger(abcWebServices.class.getName()) .log(java.util.logging.Level.INFO, "Can not initialize the default wsdl from {0}", "file:xxxxx.wsdl"); } WSDL_LOCATION = url; }
路径是file:xxxxx.wsdl,鬼知道这是什么位置。 --------------------------------------- 后来加了个参数-wsdlLocation
wsdl2java -d src-cxf -b custom.xml -exsh true -encoding utf-8 -autoNameResolution -verbose -wsdlLocation classpath:wsdl/xxxxx.wsdl xxxxx.wsdl
生成的代码是这样的:
@WebServiceClient(name = "abcWebServices", wsdlLocation = "classpath:wsdl/xxxxx.wsdl", targetNamespace = "http://xml.abc.com") public class abcWebServices extends Service {
public final static URL WSDL_LOCATION;
public final static QName SERVICE = new QName("http://xml.abc.com", "abcWebServices"); public final static QName abcWebServicesPort = new QName("http://xml.abc.com", "abcWebServicesPort"); static { URL url = abcWebServices.class.getClassLoader().getResource("wsdl/xxxxx.wsdl"); if (url == null) { java.util.logging.Logger.getLogger(abcWebServices.class.getName()) .log(java.util.logging.Level.INFO, "Can not initialize the default wsdl from {0}", "classpath:wsdl/abc.wsdl"); } WSDL_LOCATION = url; }
然后把wsdl文件和一堆xsd文件都扔到resources的wsdl目录下,确保部署后在WEB-INF/classes/wsdl目录下即可。 --------------------------------------------- custom.xml
<?xml version="1.0" encoding="UTF-8"?> <jaxws:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://java.sun.com/xml/ns/jaxws" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"> <enableWrapperStyle>false</enableWrapperStyle> </jaxws:bindings>
|