CXF提供从wsdl文件生成java代码的工具脚本:%CXF_HOME%\bin\wsdl2java.bat
脚本参数详解:
-?,-h,-help | Displays the online help for this utility and exits. |
-fe frontend-name | Specifies the frontend. Default is JAXWS. Currently supports only JAXWS frontend and a "jaxws21" frontend to generate JAX-WS 2.1 compliant code. |
-db databinding-name | Specifies the databinding. Default is jaxb. Currently supports jaxb, xmlbeans, sdo (sdo-static and sdo-dynamic), and jibx. |
-wv wsdl-version | Specifies the wsdl version .Default is WSDL1.1. Currently suppports only WSDL1.1 version. |
-p [ wsdl-namespace= ] PackageName | Specifies zero, or more, package names to use for the generated code. Optionally specifies the WSDL namespace to package name mapping. |
-sn service-name | The WSDL service name to use for the generated code. |
-b binding-name | Specifies JAXWS or JAXB binding files or XMLBeans context files. Use multiple -b flags to specify multiple entries. |
-catalog catalog-file-name | Specify catalog file to map the imported wsdl/schema |
-d output-directory | Specifies the directory into which the generated code files are written. |
-compile | Compiles generated Java files. |
-classdir compile-class-dir | Specifies the directory into which the compiled class files are written. |
-client | Generates starting point code for a client mainline. |
-clientjar jar-file-name | Generates the jar file which contains all the client classes and wsdl;the specified wsdlLocation won't work when the -clientJar is defined. |
-server | Generates starting point code for a server mainline. |
-impl | Generates starting point code for an implementation object. |
-all | Generates all starting point code: types, service proxy, service interface, server mainline, client mainline, implementation object, and an Ant build.xml file. |
-ant | Specify to generate an Ant build.xml script. |
-autoNameResolution | Automatically resolve naming conflicts without requiring the use of binding customizations. |
-defaultValues=[DefaultValueProvider impl] | Specifies that default values are generated for the impl and client. You can also provide a custom default value provider. The default provider is RandomValueProvider |
-nexclude schema-namespace [=java-packagename] | Ignore the specified WSDL schema namespace when generating code. This option may be specified multiple times. Also, optionally specifies the Java package name used by types described in the excluded namespace(s). |
-exsh (true/false) | Enables or disables processing of implicit SOAP headers (i.e. SOAP headers defined in the wsdl:binding but not wsdl:portType section.) Processing the SOAP headers requires the SOAP binding jars available on the classpath which was not the default in CXF 2.4.x and older. You may need to add a dependency to cxf-rt-binding-soap for this flag to work. Default is false. |
-dns (true/false) | Enables or disables the loading of the default namespace package name mapping. Default is true andhttp://www.w3.org/2005/08/addressing=org.apache.cxf.ws.addressing namespace package mapping will be enabled. |
-dex (true/false) | Enables or disables the loading of the default excludes namespace mapping. Default is true. |
-validate | Enables validating the WSDL before generating the code. |
-keep | Specifies that the code generator will not overwrite any preexisting files. You will be responsible for resolving any resulting compilation issues. |
-wsdlLocation wsdlLocation | Specifies the value of the @WebServiceClient annotation's wsdlLocation property. |
-xjc<xjc args> | Specifies a comma separated list of arguments that are passed directly to the XJC processor when using the JAXB databinding. A list of available XJC plugins can be obtained using -xjc-X. |
-noAddressBinding | For compatibility with CXF 2.0, this flag directs the code generator to generate the older CXF proprietary WS-Addressing types instead of the JAX-WS 2.1 compliant WS-Addressing types. |
-v | Displays the version number for the tool. |
-verbose | Displays comments during the code generation process. |
-quiet | Suppresses comments during the code generation process. |
-exceptionSuper | superclass for fault beans generated from wsdl:fault elements (defaults to java.lang.Exception) |
-reserveClass classname | Used with -autoNameResolution, defines a class names for wsdl-to-java not to use when generating classes. Use this option multiple times for multiple classes. |
-allowElementReferences<=true> | (or -aer) If true, disregards the rule given in section 2.3.1.2(v) of the JAX-WS 2.2 specification disallowing element references when using wrapper-style mapping. |
-asyncMethods=foo,bar,... | List of subsequently generated Java class methods to allow for client-side asynchronous calls, similar to enableAsyncMapping in a JAX-WS binding file. |
-bareMethods=foo,bar,... | List of subsequently generated Java class methods to have wrapper style (see below), similar to enableWrapperStyle in JAX-WS binding file. |
-mimeMethods=foo,bar,... | List of subsequently generated Java class methods to enable mime:content mapping, similar to enableMIMEContent in JAX-WS binding file. |
-faultSerialVersionUID <fault-serialVersionUID> | How to generate suid of fault exceptions. Use NONE, TIMESTAMP, FQCN, or a specific number. Default is NONE. |
-mark-generated | Adds the @Generated annotation to classes generated. |
wsdlurl | The path and name of the WSDL file to use in generating the code. |
参考地址:http://cxf.apache.org/docs/wsdl-to-java.html
【举例】
wsdl2java HelloWorld.wsdl
wsdl2java -p com.mycompany.greeting Greeting.wsdl
wsdl2java -client HelloWorld.wsdl
wsdl2java -server -b "binding.xml" -d d:\cxf sample.wsdl
SERVER端:
wsdl2java -b cxf_binding.xml -catalog cxf_catalog.xml -d server\src -server -impl -all -frontend jaxws21 -encoding utf-8 -autoNameResolution -keep example.wsdl
CLIENT端:
wsdl2java -b cxf_binding.xml -catalog cxf_catalog.xml -d client\src -client -impl -all -frontend jaxws21 -encoding utf-8 -autoNameResolution -keep example.wsdl
-impl:生成WS发布接口的实现类
-frontend jaxws21:使用JAX-WS 2.1
-encodng:生成文件的编码格式
常见问题:
1. 如何映射xsd:dateTime 到 java.util.Date 而不是 XMLGregorianCalendar ?
<jxb:bindings version="2.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <jxb:bindings schemaLocation="file:<path><name>.xsd" node="/xs:schema"> <jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <jxb:javaType name="java.util.Date" xmlType="xs:dateTime" parseMethod="org.apache.cxf.tools.common.DataTypeAdapter.parseDateTime" printMethod="org.apache.cxf.tools.common.DataTypeAdapter.printDateTime"/> </jxb:globalBindings> </jxb:bindings> </jxb:bindings>
2.如何将属性的类型直接映射为JAVA类型而不是JAXBElement?
<jaxws:bindings wsdlLocation="JVTTroubleTicketSession.wsdl" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> <jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema" > <jxb:globalBindings generateElementProperty="false" > </jxb:globalBindings> </jaxws:bindings> </jaxws:bindings>
3.常见绑定文件及参数解释。
<?xml version="1.0" encoding="UTF-8"?> <jxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" version="2.1"> <jxb:globalBindings fixedAttributeAsConstantProperty="true" typesafeEnumMaxMembers="300" typesafeEnumMemberName="generateName" enableFailFastCheck="false" generateIsSetMethod="false" underscoreBinding="asCharInWord" choiceContentProperty="false" generateElementProperty="false"> <jxb:javaType name="java.util.Calendar" xmlType="xs:dateTime" parseMethod="javax.xml.bind.DatatypeConverter.parseDate" printMethod="javax.xml.bind.DatatypeConverter.printDate" /> </jxb:globalBindings> </jxb:bindings>
相关推荐
### Apache CXF wsdl2java 工具使用详解 #### 一、Apache CXF 概述 Apache CXF 是一个高性能、轻量级的开源框架,用于构建和使用基于 SOAP 和 REST 规范的 Web 服务。CXF 提供了强大的功能支持,包括 XML 数据的...
【标题】:“使用CXF:Java 2 WSDL” 【描述】:在Java开发中,Apache CXF是一个广泛使用的开源框架,它允许开发者构建和部署Web服务。"Java 2 WSDL"指的是从Java类生成WSDL(Web Services Description Language)...
**WSDL2Java工具详解** 在IT行业中,Web服务(Web Service)是一种通过网络进行通信的标准接口,使得不同系统之间可以实现数据交换和业务协同。其中,WSDL(Web Services Description Language)是用于定义Web服务...
**WSDL2Java工具详解** 在Web服务的世界中,`WSDL`(Web Service Description Language)是一种XML格式的规范,用于定义服务接口、操作、消息结构等,使得服务消费者能够理解如何与服务进行交互。而`WSDL2Java`工具...
WSDL2Java工具详解 WSDL(Web Services Description Language)是一种XML格式,用于定义网络服务的接口。它描述了服务的端点、消息格式、操作和协议绑定等关键信息,使得客户端能够理解如何与服务进行通信。WSDL2...
**WSDL2Java生成工具详解** 在分布式系统和Web服务领域,WSDL(Web Services Description Language)是一种XML格式,用于定义服务接口、消息结构和通信协议。WSDL2Java工具是Apache CXF框架的一部分,它允许开发者...
**WSDL2Java工具详解** 在IT行业中,Web服务是一个重要的接口交互方式,它使得不同系统之间能够通过标准协议进行数据交换。WSDL(Web Services Description Language)是用于定义Web服务接口的一种XML格式,它详细...
### CXF生成的WSDL详解 #### 一、概述 WSDL(Web Services Description Language)是一种用于描述Web服务的标准XML格式。它包含了服务提供者如何访问该服务的信息,包括服务的位置、服务可用的方法以及这些方法...
本文将详细介绍三种基于WSDL生成WebService服务端的方法:使用`wsdl2java`命令、通过SOAPUI工具及借助MyEclipse的Web Service项目功能。 #### 方法一:使用`wsdl2java`命令生成 `wsdl2java`是Apache CXF提供的一个...
**WSDL2Java工具详解** 在IT行业中,Web服务是一个重要的通信方式,它允许不同的系统通过互联网进行数据交换。WSDL(Web Services Description Language)是用于定义Web服务接口的一种XML格式,它描述了服务的位置...
5. **测试服务**:可以使用CXF的客户端工具(如wsdl2java生成客户端代码)或手动编写HTTP请求来测试服务。 **四、CXF的WsdlFirst开发** 除了JavaFirst开发方式,CXF还支持WsdlFirst,即先有WSDL(Web Service ...
### CXF服务端WSDL发布及代码生成详解 #### 一、概述 在现代软件开发中,特别是企业级应用开发领域,Web服务扮演着至关重要的角色。CXF(Camel and XFire)作为Apache下的一个开源项目,为开发高质量的Web服务提供...
总之,本文档为Java开发者提供了两种调用wsdl的方式,并着重讲解了使用cxf的wsdl2java工具生成本地类的过程,详细描述了在实际操作中可能遇到的问题以及相对应的解决方案。对于希望使用Java语言调用外部WSDL接口的...
根据提供的标题、描述、标签及部分内容,我们可以了解到这段信息与CXF工具中的`wsdl2java.bat`命令有关。此命令用于将Web服务定义语言(WSDL)文件转换为Java代码,以便在Java应用程序中使用这些Web服务。下面将详细...
例如,可以使用CXF的wsdl2java工具将WSDL转换为Java源代码。此外,CXF还支持动态客户端,即在运行时动态创建和使用Web服务,这在处理未知服务或者需要灵活调整服务调用时非常有用。 总的来说,Apache CXF 2.4.3为...
其中,“wsdl2java”工具就是CXF提供的一个非常实用的功能,它可以根据WSDL文件自动生成客户端和服务端所需的Java代码。本文将详细介绍如何使用CXF的“wsdl2java”工具来生成Webservice客户端代码。 #### 二、基础...
【CXF小案例:Java WebService详解】 在Java开发中,Apache CXF是一个非常流行的开源框架,用于构建和消费Web服务。本篇文章将深入探讨如何使用CXF来创建一个简单的Java WebService,并介绍相关的知识点。 一、...
【Java WebService 源码使用 CXF 框架详解】 Java WebService 是一种基于标准的、平台无关的通信方式,它允许不同系统间的应用程序通过网络交换数据。CXF 是一个开源的 Java 库,它提供了创建和消费 WebService 的...
【Java编写的CXF实例详解】 Java编程语言在企业级应用开发中占据着重要的地位,尤其是在Web服务领域。CXF,全称为CXF框架(Apache CXF),是一个强大的开源Java框架,用于构建和消费Web服务。它允许开发者通过Java ...