CXF 教程(一)


CXF Web Service 简单示例


http://cxf.apache.org 下载 CXF
  • 在 Eclipse 中配置 Maven 插件
  • Java to WS

    在 2.1 以前的版本中命令为 java2wsdl,在新的版本中为 java2ws

    java2ws 用于生成 Web service endpoint's implementation (SEI) 类并根据这些类生成 WSDL 文件, Bean 封装类, 用于启动服务的服务端代码和客户端方问代码。

    5.1.2 语法

    语法如下所示:

    java2ws -databinding  -frontend  
            -wsdl -wrapperbean -client -server -ant -o 
            -d  -classdir  
            -cp  -soap12 -t  
            -beans * 
            -address  -servicename  
            -portname  -createxsdimports -h -v -verbose 
            -quiet {classname}
    

    5.1.3 参数说明

    各参数说明如下:

    Option

    Interpretation

    -?,-h,-help

    Displays the online help for this utility and exits.

    -o

    Specifies the name of the generated WSDL file.

    --databinding

    Specify the data binding (aegis or jaxb). Default is jaxb for jaxws frontend, and aegis for simple frontend.

    -frontend

    Specify the frontend to use. jaxws and the simple frontend are supported.

    -wsdl

    Specify to generate the WSDL file.

    -wrapperbean

    Specify to generate the wrapper and fault bean

    -client

    Specify to generate client side code

    -server

    Specify to generate server side code

    -ant

    Specify to generate an Ant build.xml script

    -cp

    Specify the SEI and types class search path of directories and zip/jar files.

    -soap12

    Specifies that the generated WSDL is to include a SOAP 1.2 binding.

    -t

    Specifies the target namespace to use in the generated WSDL file.

    -servicename

    Specifies the value of the generated service element's name attribute.

    -v

    Displays the version number for the tool.

    -verbose

    Displays comments during the code generation process.

    -quiet

    Suppresses comments during the code generation process.

    -s

    The directory in which the generated source files(wrapper bean ,fault bean ,client side or server side code) are placed.

    -classdir

    The directory in which the generated sources are compiled into. If not specified, the files are not compiled.

    -portname

    Specify the port name to use in the generated wsdl.

    -address

    Specify the port address.

    -beans

    Specify the pathname of a file defining additional Spring beans to customize databinding configuration.

    -createxsdimports

    Output schemas to separate files and use imports to load them instead of inlining them into the wsdl.

    -d

    The directory in which the resource files are placed, wsdl file will be placed into this directory by default

    classname

    Specifies the name of the SEI class.

    5.1.4 示例

    java2ws -wsdl -d ./resources lld.cxf.service.HelloService
    java2wsdl -cp ./tmp org.apache.hello_world_soap_http.Greeter
    java2wsdl -o hello.wsdl org.apache.hello_world_soap_http.Greeter
    java2wsdl -o hello.wsdl -t http://cxf.apache.org org.apache.hello_world_soap_http.Greeter
    

    5.1.5 与 Ant 集成

    <?xml version="1.0"?>
    name="cxf java2ws" basedir=".">   
       name="cxf.home" location ="/usr/myapps/cxf-trunk"/>
       name="build.classes.dir" location ="${basedir}/build/classes"/>
       id="cxf.classpath">
          location="${build.classes.dir}"/>
          dir="${cxf.home}/lib">
             name="*.jar"/>
          
       
          
       name="cxfJavaToWS">
          classname="org.apache.cxf.tools.java2ws.JavaToWS" fork="true">
             value="-wsdl"/>
             value="-o"/>
             value="hello.wsdl"/>
             value="service.Greeter"/>
             
                refid="cxf.classpath"/>