【轉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查看
- 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
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查看
- Usage: wsimport [options] <WSDL_URI>
- where [options] include:
- -b <path> specify external jaxws or jaxb binding files
- (Each <file> must have its own -b)
- -catalog <file> specify catalog file to resolve external entity refe
- rences
- supports TR9401, XCatalog, and OASIS XML Catalog for
- mat.
- -d <directory> specify where to place generated output files
- -extension allow vendor extensions - functionality not specifie
- d
- by the specification. Use of extensions may
- result in applications that are not portable or
- may not interoperate with other implementations
- -help display help
- -httpproxy:<host>:<port> specify a HTTP proxy server (port defaults to 8080)
- -keep keep generated files
- -p <pkg> specifies the target package
- -s <directory> specify where to place generated source files
- -verbose output messages about what the compiler is doing
- -version print version information
- -wsdllocation <location> @WebService.wsdlLocation and @WebServiceClient.wsdlL
- ocation value
- Examples:
- wsimport stock.wsdl -b stock.xml -b stock.xjb
- wsimport -d generated http://example.org/stock?wsdl