wsgen与wsimport命令简单说明

【转http://zhuchengzzcc.iteye.com/blog/1535066

wsgen 
wsgen 是在JDK的bin目录下的一个exe文件(Windows版),该命 令的主要功能是用来生成合适的JAX-WS。它读取Web Service的终端类文件,同时生成所有用于发布Web Service所依赖的源代码文件和经过编译过的二进制类文件。这里要特别说明的是,通常在Web Service Bean中用到的异常类会另外生成一个描述Bean,如果Web Service Bean中的方法有申明抛出异常,这一步是必需的,否则服务器无法绑定该对像。此外,wsgen 还能辅助生成WSDL和相关的xsd文件。wsgen 从资源文件生成一个完整的操作列表并验证web service是否合法,可以完整发布。 
命令参数说明:

  •  -cp 定义classpath
  •  -r 生成 bean的wsdl文件的存放目录
  •  -s 生成发布Web Service的源代码文件的存放目录(如果方法有抛出异常,则会生成该异常的描述类源文件)
  •  -d 生成发布Web Service的编译过的二进制类文件的存放目录(该异常的描述类的class文件)


命令范例: wsgen -cp ./bin -r ./wsdl -s ./src -d ./bin -wsdl org.jsoso.jws.server.Example 

 PS:如果发布webservice的java类的方法中有异常声明时,是不能直接发布成webservice的,需要用wsgen命令生成相应的异常处理的类。

   wsgen 命令 可以为我们生成wsdl 和异常处理的类

   如: class目录结构如下:calsses\com\michael\MessageJws.class 
在执行下面的命令之前需要新建文件夹classes\wsdl\,用来存放生成wsdl文件
如果创建文件夹classes\bin\classes\src\:...\classes>执行下面的命令

 wsgen -cp . -r ./wsdl -s ./src -d ./bin -wsdl com.michael.MessageJws

如果不创建上面的src、bin文件夹则可以: ...\classes>执行下面的命令:

wsgen -cp . -r ./wsdl -s ./ -d ./ -wsdl com.michael.MessageJws 

   这时在 calsses\com\michael\ 下看到生成了新的文件夹jaxws,jaxws目录下的文件如下:

  同时在刚才新建的 classes\wsdl\ 下生成了两个wsdl相关文件
MessageJwsService.wsdl 和 MessageJwsService_schema1.xsd


具体使用方式可以使用wsgen -help查看

Java代码 复制代码  收藏代码
  1. Usage: wsgen [options] <SEI>   
  2.   
  3. where [options] include:   
  4.   -classpath <path>          specify where to find input class files   
  5.   -cp <path>                 same as -classpath <path>   
  6.   -d <directory>             specify where to place generated output files   
  7.   -extension                 allow vendor extensions - functionality not specifi   
  8. ed   
  9.                              by the specification.  Use of extensions may   
  10.                              result in applications that are not portable or   
  11.                              may not interoperate with other implementations   
  12.   -help                      display help   
  13.   -keep                      keep generated files   
  14.   -r <directory>             resource destination directory, specify where to   
  15.                              place resouce files such as WSDLs   
  16.   -s <directory>             specify where to place generated source files   
  17.   -verbose                   output messages about what the compiler is doing   
  18.   -version                   print version information   
  19.   -wsdl[:protocol]           generate a WSDL file.  The protocol is optional.   
  20.                              Valid protocols are soap1.1 and Xsoap1.2, the defau   
  21. lt   
  22.                              is soap1.1.  Xsoap1.2 is not standard and can only   
  23. be   
  24.                              used in conjunction with the -extension option   
  25.   -servicename <name>        specify the Service name to use in the generated WS   
  26. DL   
  27.                              Used in conjunction with the -wsdl option.   
  28.   -portname <name>           specify the Port name to use in the generated WSDL   
  29.                              Used in conjunction with the -wsdl option.   
  30.   
  31. Examples:   
  32.   wsgen -cp . example.Stock   
  33.   wsgen -cp . example.Stock -wsdl -servicename {http://mynamespace}MyService  
Usage: wsgen [options] <SEI>

where [options] include:
  -classpath <path>          specify where to find input class files
  -cp <path>                 same as -classpath <path>
  -d <directory>             specify where to place generated output files
  -extension                 allow vendor extensions - functionality not specifi
ed
                             by the specification.  Use of extensions may
                             result in applications that are not portable or
                             may not interoperate with other implementations
  -help                      display help
  -keep                      keep generated files
  -r <directory>             resource destination directory, specify where to
                             place resouce files such as WSDLs
  -s <directory>             specify where to place generated source files
  -verbose                   output messages about what the compiler is doing
  -version                   print version information
  -wsdl[:protocol]           generate a WSDL file.  The protocol is optional.
                             Valid protocols are soap1.1 and Xsoap1.2, the defau
lt
                             is soap1.1.  Xsoap1.2 is not standard and can only
be
                             used in conjunction with the -extension option
  -servicename <name>        specify the Service name to use in the generated WS
DL
                             Used in conjunction with the -wsdl option.
  -portname <name>           specify the Port name to use in the generated WSDL
                             Used in conjunction with the -wsdl option.

Examples:
  wsgen -cp . example.Stock
  wsgen -cp . example.Stock -wsdl -servicename {http://mynamespace}MyService


wsimport 
wsimport也是在JDK的bin目录下的一个exe文件(Windows版),主要功能是根据服务端发布的wsdl文件生成客户端存根及框架,负责 与Web Service 服务器通信,并在将其封装成实例,客户端可以直接使用,就像使用本地实例一样。对Java而言,wsimport帮助程序员生存调用web service所需要的客户端类文件.java和.class。要提醒指出的是,wsimport可以用于非Java的服务器端,如:服务器端也许是C# 编写的web service,通过wsimport则生成Java的客户端实现。 
命令参数说明:

  •  -d 生成客户端执行类的class文件的存放目录
  •  -s 生成客户端执行类的源文件的存放目录
  •  -p 定义生成类的包名


命令范例: wsimport -d ./bin -s ./src -p org.jsoso.jws.client.ref http://localhost:8080/hello?wsdl

下面2种方式都是正确的。

wsimport -d ./bin -s ./src -p com.michael.messageclient http://localhost:8088/messagejws?wsdl    

wsimport -d ./bin -s ./src -p com.michael.messageclient ./wsdl/MessageJwsService.wsdl

具体使用方式可以使用wsimport -help查看

Java代码 复制代码  收藏代码
  1. Usage: wsimport [options] <WSDL_URI>   
  2.   
  3. where [options] include:   
  4.   -b <path>                 specify external jaxws or jaxb binding files   
  5.                             (Each <file> must have its own -b)   
  6.   -catalog <file>           specify catalog file to resolve external entity refe   
  7. rences   
  8.                             supports TR9401, XCatalog, and OASIS XML Catalog for  
  9. mat.   
  10.   -d <directory>            specify where to place generated output files   
  11.   -extension                allow vendor extensions - functionality not specifie   
  12. d   
  13.                             by the specification.  Use of extensions may   
  14.                             result in applications that are not portable or   
  15.                             may not interoperate with other implementations   
  16.   -help                     display help   
  17.   -httpproxy:<host>:<port>  specify a HTTP proxy server (port defaults to 8080)   
  18.   -keep                     keep generated files   
  19.   -p <pkg>                  specifies the target package  
  20.   -s <directory>            specify where to place generated source files   
  21.   -verbose                  output messages about what the compiler is doing   
  22.   -version                  print version information   
  23.   -wsdllocation <location>  @WebService.wsdlLocation and @WebServiceClient.wsdlL   
  24. ocation value   
  25.   
  26. Examples:   
  27.   wsimport stock.wsdl -b stock.xml -b stock.xjb   
  28.   wsimport -d generated http://example.org/stock?wsdl  

wsgen 
wsgen 是在JDK的bin目录下的一个exe文件(Windows版),该命 令的主要功能是用来生成合适的JAX-WS。它读取Web Service的终端类文件,同时生成所有用于发布Web Service所依赖的源代码文件和经过编译过的二进制类文件。这里要特别说明的是,通常在Web Service Bean中用到的异常类会另外生成一个描述Bean,如果Web Service Bean中的方法有申明抛出异常,这一步是必需的,否则服务器无法绑定该对像。此外,wsgen 还能辅助生成WSDL和相关的xsd文件。wsgen 从资源文件生成一个完整的操作列表并验证web service是否合法,可以完整发布。 
命令参数说明:

  •  -cp 定义classpath
  •  -r 生成 bean的wsdl文件的存放目录
  •  -s 生成发布Web Service的源代码文件的存放目录(如果方法有抛出异常,则会生成该异常的描述类源文件)
  •  -d 生成发布Web Service的编译过的二进制类文件的存放目录(该异常的描述类的class文件)


命令范例: wsgen -cp ./bin -r ./wsdl -s ./src -d ./bin -wsdl org.jsoso.jws.server.Example 

 PS:如果发布webservice的java类的方法中有异常声明时,是不能直接发布成webservice的,需要用wsgen命令生成相应的异常处理的类。

   wsgen 命令 可以为我们生成wsdl 和异常处理的类

   如: class目录结构如下:calsses\com\michael\MessageJws.class 
在执行下面的命令之前需要新建文件夹classes\wsdl\,用来存放生成wsdl文件
如果创建文件夹classes\bin\classes\src\:...\classes>执行下面的命令

 wsgen -cp . -r ./wsdl -s ./src -d ./bin -wsdl com.michael.MessageJws

如果不创建上面的src、bin文件夹则可以: ...\classes>执行下面的命令:

wsgen -cp . -r ./wsdl -s ./ -d ./ -wsdl com.michael.MessageJws 

   这时在 calsses\com\michael\ 下看到生成了新的文件夹jaxws,jaxws目录下的文件如下:

  同时在刚才新建的 classes\wsdl\ 下生成了两个wsdl相关文件
MessageJwsService.wsdl 和 MessageJwsService_schema1.xsd


具体使用方式可以使用wsgen -help查看

Java代码 复制代码  收藏代码
  1. Usage: wsgen [options] <SEI>   
  2.   
  3. where [options] include:   
  4.   -classpath <path>          specify where to find input class files   
  5.   -cp <path>                 same as -classpath <path>   
  6.   -d <directory>             specify where to place generated output files   
  7.   -extension                 allow vendor extensions - functionality not specifi   
  8. ed   
  9.                              by the specification.  Use of extensions may   
  10.                              result in applications that are not portable or   
  11.                              may not interoperate with other implementations   
  12.   -help                      display help   
  13.   -keep                      keep generated files   
  14.   -r <directory>             resource destination directory, specify where to   
  15.                              place resouce files such as WSDLs   
  16.   -s <directory>             specify where to place generated source files   
  17.   -verbose                   output messages about what the compiler is doing   
  18.   -version                   print version information   
  19.   -wsdl[:protocol]           generate a WSDL file.  The protocol is optional.   
  20.                              Valid protocols are soap1.1 and Xsoap1.2, the defau   
  21. lt   
  22.                              is soap1.1.  Xsoap1.2 is not standard and can only   
  23. be   
  24.                              used in conjunction with the -extension option   
  25.   -servicename <name>        specify the Service name to use in the generated WS   
  26. DL   
  27.                              Used in conjunction with the -wsdl option.   
  28.   -portname <name>           specify the Port name to use in the generated WSDL   
  29.                              Used in conjunction with the -wsdl option.   
  30.   
  31. Examples:   
  32.   wsgen -cp . example.Stock   
  33.   wsgen -cp . example.Stock -wsdl -servicename {http://mynamespace}MyService  
Usage: wsgen [options] <SEI>

where [options] include:
  -classpath <path>          specify where to find input class files
  -cp <path>                 same as -classpath <path>
  -d <directory>             specify where to place generated output files
  -extension                 allow vendor extensions - functionality not specifi
ed
                             by the specification.  Use of extensions may
                             result in applications that are not portable or
                             may not interoperate with other implementations
  -help                      display help
  -keep                      keep generated files
  -r <directory>             resource destination directory, specify where to
                             place resouce files such as WSDLs
  -s <directory>             specify where to place generated source files
  -verbose                   output messages about what the compiler is doing
  -version                   print version information
  -wsdl[:protocol]           generate a WSDL file.  The protocol is optional.
                             Valid protocols are soap1.1 and Xsoap1.2, the defau
lt
                             is soap1.1.  Xsoap1.2 is not standard and can only
be
                             used in conjunction with the -extension option
  -servicename <name>        specify the Service name to use in the generated WS
DL
                             Used in conjunction with the -wsdl option.
  -portname <name>           specify the Port name to use in the generated WSDL
                             Used in conjunction with the -wsdl option.

Examples:
  wsgen -cp . example.Stock
  wsgen -cp . example.Stock -wsdl -servicename {http://mynamespace}MyService


wsimport 
wsimport也是在JDK的bin目录下的一个exe文件(Windows版),主要功能是根据服务端发布的wsdl文件生成客户端存根及框架,负责 与Web Service 服务器通信,并在将其封装成实例,客户端可以直接使用,就像使用本地实例一样。对Java而言,wsimport帮助程序员生存调用web service所需要的客户端类文件.java和.class。要提醒指出的是,wsimport可以用于非Java的服务器端,如:服务器端也许是C# 编写的web service,通过wsimport则生成Java的客户端实现。 
命令参数说明:

  •  -d 生成客户端执行类的class文件的存放目录
  •  -s 生成客户端执行类的源文件的存放目录
  •  -p 定义生成类的包名


命令范例: wsimport -d ./bin -s ./src -p org.jsoso.jws.client.ref http://localhost:8080/hello?wsdl

下面2种方式都是正确的。

wsimport -d ./bin -s ./src -p com.michael.messageclient http://localhost:8088/messagejws?wsdl    

wsimport -d ./bin -s ./src -p com.michael.messageclient ./wsdl/MessageJwsService.wsdl

具体使用方式可以使用wsimport -help查看

Java代码 复制代码  收藏代码
  1. Usage: wsimport [options] <WSDL_URI>   
  2.   
  3. where [options] include:   
  4.   -b <path>                 specify external jaxws or jaxb binding files   
  5.                             (Each <file> must have its own -b)   
  6.   -catalog <file>           specify catalog file to resolve external entity refe   
  7. rences   
  8.                             supports TR9401, XCatalog, and OASIS XML Catalog for  
  9. mat.   
  10.   -d <directory>            specify where to place generated output files   
  11.   -extension                allow vendor extensions - functionality not specifie   
  12. d   
  13.                             by the specification.  Use of extensions may   
  14.                             result in applications that are not portable or   
  15.                             may not interoperate with other implementations   
  16.   -help                     display help   
  17.   -httpproxy:<host>:<port>  specify a HTTP proxy server (port defaults to 8080)   
  18.   -keep                     keep generated files   
  19.   -p <pkg>                  specifies the target package  
  20.   -s <directory>            specify where to place generated source files   
  21.   -verbose                  output messages about what the compiler is doing   
  22.   -version                  print version information   
  23.   -wsdllocation <location>  @WebService.wsdlLocation and @WebServiceClient.wsdlL   
  24. ocation value   
  25.   
  26. Examples:   
  27.   wsimport stock.wsdl -b stock.xml -b stock.xjb   
  28.   wsimport -d generated http://example.org/stock?wsdl  

猜你喜欢

转载自icourses.iteye.com/blog/1677507