我有一个 Ant 任务,它需要一个 wsdl 文件并且应该自动生成 POJO(客户端 Java),所以我可以开始编写我的客户端 JAX-WS Web 服务。
但是我收到一个错误“[错误] 包名称....用于此架构不是有效的包名称”
仅当我的wsdl文件中包含 1 个以上的模式导入时才会发生此错误,例如
<xsd:import namespace="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Response" schemaLocation="ProcessCustomerInquiryResponse.xsd"/>
<xsd:import namespace="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Request" schemaLocation="ProcessCustomerInquiryRequest.xsd"/>
</xsd:schema>
下面是整个wsdl
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:CMSLINK="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry" xmlns:REQ="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Request" xmlns:RESP="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Response" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry" name="ProcessCustomerInquiryService">
<wsdl:types>
<xsd:schema>
<xsd:import namespace="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Response" schemaLocation="ProcessCustomerInquiryResponse.xsd"/>
<xsd:import namespace="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Request" schemaLocation="ProcessCustomerInquiryRequest.xsd"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="ProcessCustomerInquiryRequest">
<wsdl:part name="requestData" element="REQ:ProcessCustomerInquiryRequest"/>
</wsdl:message>
<wsdl:message name="ProcessCustomerInquiryResponse">
<wsdl:part name="responseData" element="RESP:ProcessCustomerInquiryResponse"/>
</wsdl:message>
<wsdl:portType name="ESB_ProcessCustomerInquiryService">
<wsdl:operation name="ReqResp">
<wsdl:input name="processRequest" message="CMSLINK:ProcessCustomerInquiryRequest"/>
<wsdl:output name="processResponse" message="CMSLINK:ProcessCustomerInquiryResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ProcessCustomerInquiryServiceSoapBinding" type="CMSLINK:ESB_ProcessCustomerInquiryService">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ReqResp">
<wsdlsoap:operation soapAction="process"/>
<wsdl:input>
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ProcessCustomerInquiryService">
<wsdl:port name="ProcessCustomerInquiry" binding="CMSLINK:ProcessCustomerInquiryServiceSoapBinding">
<wsdlsoap:address location="http://tsesbd01.tms.toyota.com:51180/v2/MF_CMSLINK_ProcessCustomerInquiryDistributed.msgflow"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
XJC Ant 任务
<project name="WSDLCompile" default="wsdl2java" basedir=".">
<target name="wsdl2java" description="Run xjc -wsdl.">
<!-- properties -->
<property name="sourceDir" value="temp/src" />
<echo message="sourceDir:"/>
<echo message="${sourceDir}"/>
<mkdir dir="temp/classes"/>
<property name="outputDir" value="temp/classes" />
<echo message="outputDir:"/>
<echo message="${outputDir}"/>
<!-- xjc properties -->
<property name="wsdl.url" value="src/wsdl/cmslink/ProcessCustomerInquiry.wsdl" />
<echo message="wsdl.url:"/>
<echo message="${wsdl.url}"/>
<property name="wsdl.mapping.package.response" value="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Response=com.tms.cmslink.rts.service.ProcessCustomerInquiry.Response" />
<echo message="wsdl.mapping.package.response:"/>
<property name="wsdl.mapping.package.request" value="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Request=com.tms.cmslink.rts.service.ProcessCustomerInquiry.Request" />
<echo message="wsdl.mapping.package.request:"/>
<!--C:/Program Files/Java/jdk1.7.0_09/bin/xjc -->
<!--xjc execution-->
<exec executable="xjc">
<arg value="-wsdl" />
<arg value="${wsdl.url}" />
<arg value="-d" />
<arg value="${outputDir}" />
<arg value="-p"/>
<arg value="${wsdl.mapping.package.request}"/>
<arg value="-p"/>
<arg value="${wsdl.mapping.package.response}"/>
<arg value="-verbose"/>
</exec>
</target>
</project>
如果我删除额外的模式导入response.xsd或request.xsd,并且还只包含 1 个用于 ANT 任务的“-p”包命名空间参数,那么 ANT 运行时不会出错,但是我的 wsdl 文件包含多个模式导入。
编辑
我更改了“-p”参数的值以遵守包约定,尽管我之前的方法是基于 JXC 错误论坛。
<project name="WSDLCompile" default="wsdl2java" basedir=".">
<target name="wsdl2java" description="Run xjc -wsdl.">
<!-- properties -->
<property name="sourceDir" value="temp/src" />
<echo message="sourceDir:"/>
<echo message="${sourceDir}"/>
<mkdir dir="temp/classes"/>
<property name="outputDir" value="temp/classes" />
<echo message="outputDir:"/>
<echo message="${outputDir}"/>
<!-- xjc properties -->
<property name="wsdl.url" value="src/wsdl/cmslink/ProcessCustomerInquiry.wsdl" />
<echo message="wsdl.url:"/>
<echo message="${wsdl.url}"/>
<property name="wsdl.mapping.package.response" value="com.tms.cmslink.rts.service.ProcessCustomerInquiry.Response" />
<echo message="wsdl.mapping.package.response:"/>
<property name="wsdl.mapping.package.request" value="com.tms.cmslink.rts.service.ProcessCustomerInquiry.Request" />
<echo message="wsdl.mapping.package.request:"/>
<!--C:/Program Files/Java/jdk1.7.0_09/bin/xjc -->
<!--xjc execution-->
<exec executable="xjc">
<arg value="-wsdl" />
<arg value="${wsdl.url}" />
<arg value="-d" />
<arg value="${outputDir}" />
<arg value="-p"/>
<arg value="${wsdl.mapping.package.request}"/>
<arg value="-p"/>
<arg value="${wsdl.mapping.package.response}"/>
<arg value="-verbose"/>
</exec>
</target>
</project>
我什至尝试过上面的蚂蚁任务,
-p <arg value="${wsdl.mapping.package.request }"/>
<arg value="${wsdl.mapping.package.response}"/>
通过将两个包名称放在以空格分隔的 1 行,这是根据 JXC 文档,解释说您可以拥有“零个或多个包名称空间以空格分隔”。我要求 XJC 能够处理超过 1 个模式导入。