wsimport command for JAX-WS applications
The wsimport command-line tool processes an existing Web Services Description Language (WSDL) file and generates the required artifacts for developing Java™ API for XML-Based Web Services (JAX-WS) web service applications. The generated artifacts are Java 5 compliant, making them portable across different Java versions and platforms.
The wsimport command-line tool supports the top-down approach to developing JAX-WS web services. When you start with an existing WSDL file, use the wsimport command-line tool to generate the required JAX-WS artifacts.
支援的配置: z/OS® 平台不支援 wsimport、wsgen、schemagen 和 xjc 指令行工具。
這項功能是由隨執行於 z/OS 平台的 WebSphere® Application Server 提供的組合工具所提供。請閱讀 JAX-WS 應用程式的這些指令行工具以進一步瞭解這些工具。sptcfg
最佳作法: WebSphere Application Server 提供 Java API for XML-Based Web Services (JAX-WS) 和 Java Architecture for XML Binding (JAXB) 工具。
wsimport、wsgen、schemagen 和 xjc 指令行工具位於 WebSphere Application Server 傳統版的 app_server_root\bin\ 目錄中。
xjc 和 schemagen 指令位於 Liberty 設定檔的 app_server_root\jaxb\bin\ 目錄中。
在某些情況下,WebSphere Application Server 和 JDK 提供的工具所產生的構件,支援相同層次的規格。一般而言,JDK 工具所產生的構件可以在其他標準執行時期環境之間轉移。
不過,最好的作法是利用這個產品所提供的工具來實現在 WebSphere Application Server 環境內的緊密整合,以及使用可能只在 WebSphere Application Server 環境內受到支援的特性。
如果要利用 JAX-WS 和 JAXB 2.2 版工具,請使用在 app_server_root\bin\ 目錄內之應用程式伺服器所提供的工具。bprac- Service Endpoint Interface (SEI) - The SEI is the annotated Java representation of the WSDL file for the web service. This interface is used for implementing JavaBeans endpoints or creating dynamic proxy client instances.
- javax.xml.ws.Service extension class - This is a generated class that extends the javax.xml.ws.Service class. This class is used to configure and create both dynamic proxy and dispatch instances.
- required data beans, including any Java Architecture for XML Binding (JAXB) beans that are required to model the web service data.
支援的配置: To correctly use the wsimport tool, you must adhere to the following requirements:- You must define all your services within the main WSDL file. Services that are defined within an imported WSDL file are not processed by the wsimport tool.
- If you run the wsimport tool on a WSDL file that implements a Document or Literal style pattern, the complexTypes elements that define the input and output types must be composed of unique names to prevent naming conflicts in the parameter list for the operation.
- If you run the wsimport tool and pass a ?wsdl Uniform Resource Identifier (URI) as a parameter for a WSDL file, ensure that you are using the actual resolved WSDL URI. In the full profile, the wsimport tool correctly resolves the ?wsdl URI, but other relative URIs that are referenced might not resolve correctly. In the Liberty profile, the wsimport tool correctly resolves the ?wsdl URI and other relative URIs that are referenced.
除了使用來自指令行的工具外,您也可以從 Ant 建置環境內,為 WebSphere Application Server 傳統版呼叫這些 JAX-WS 工具。在 Ant 建置環境中,使用 com.sun.tools.ws.ant.WsImport Ant 作業來呼叫 WsImport 工具。為了讓功能正常運作,這項 Ant 作業需要您使用 ws_ant Script 來呼叫 Ant。
Syntax
The command-line syntax is:
![[Windows]](../images/windows.gif)
app_server_root\bin\wsimport.bat [options] WSDL_URI
![[AIX]](../images/aixlogo.gif)
![[HP-UX]](../images/hpux.gif)
![[Linux]](../images/linux.gif)
![[Solaris]](../images/solaris.gif)
app_server_root/bin/wsimport.sh [options] WSDL_URI
![[IBM i]](../images/iseries.gif)
app_server_root/bin/wsimport [options] WSDL_URI
Parameters
The WSDL_URI is the only parameter that is required. The following parameters are optional for the wsimport command:
- -b <path>
- Specifies the external JAX-WS or JAXB binding files. You can specify multiple JAX-WS and JAXB binding files by using the -b option; however, each file must be specified with its own -b option.
- -B <jaxbOption>
- Specifies to pass this option to the JAXB schema compiler.
- -catalog
- Specifies the catalog file to resolve external entity references. It supports the TR9401, XCatalog, and the OASIS XML Catalog formats
- -d <directory>
- Specifies where to place the generated output files.
- -extension
- Specifies whether to accept custom extensions for functionality that are not specified by the JAX-WS specification. The use of custom extensions can result in applications that are not portable or do not interoperate with other implementations.
- -help
- Displays the help menu.
- -httpproxy:<host>:<port>
- Specifies an HTTP proxy. The default port value is 8080.
- -keep
- Specifies whether to keep the generated source files.
- -p <package_name>
- Specifies a target package with this command-line option and overrides any WSDL file and schema binding customization for the package name and the default package name algorithm defined in the JAX-WS specification.
- -quiet
- Specifies to suppress the wsimport output.
- -s <directory>
- Specifies the directory to place the generated source files.
- -target <version>
- Specifies to generate code that is compliant with a specific JAX-WS specification level. Specify version 2.0 or 2.1 to generate code that is compliant with the JAX-WS 2.0 or JAX-WS 2.1 specification respectively. Specifying version 2.1 indicates to generate code that is compliant with the JAX-WS 2.1 specification. The default value is version 2.2 and generates compliant code for the JAXB 2.2 specification.
- The target option is required for Liberty profile.
- -verbose
- Specifies to output messages about what the compiler is doing.
- -version
- Prints the version information. If you specify this option, only the version information is included in the output and normal command processing does not occur.
- -wsdlLocation
- Specifies the @WebServiceClient.wsdlLocation value.
支援的配置: The wsimport tool does not set
the @WebService.wsdlLocation value either by default
or when the -wsdlLocation attribute is specified. The wsimport command-line tool updates the @WebServiceClient.wsdlLocation annotation
only. You can manually update the @WebService.wsdlLocation annotation
with a relative URL that specifies the location of the Web Services
Description Language (WSDL) file. If the @WebService.wsdlLocation
annotation is present on an endpoint implementation class, then the
value must be a relative URL and the WSDL document that it references
must be packaged with the application.sptcfg
避免困難: If you specify an HTTPS URL for the -wsdlLocation
parameter, the wsimport tool generates a service
class with a no-argument constructor that is not valid. Avoid using
the no-argument service constructor to instantiate your service.
Instead, pass the HTTPS URL to one of the service class constructors
that takes a WSDL URL for an argument; for example:
gotchaMyService("https://example.ibm.com/My?wsdl"); - -clientJar
- wsimport on service WSDL generates the necessary classes that are needed for web service invocation. But not all the information that is required by the JAX-WS runtime is captured in the SEI or the WebServiceClient through standard web service annotations. The generated class has the location of the WSDL, so that it can retrieve the additional metadata of the service at runtime. However, an extra connection is required just to access the metadata each time a service instance is created, which increases the network usage. By using the -clientJar option for wsimport, the WSDL and schema are automatically downloaded and all the generated client-side artifacts are packaged into a JAR file. Therefore, you can include the generated JAR file by using this new option in the class path and do not need to fetch the WSDLs from the end point each time a service instance is created, thus saving on network usage.

參照主題