我有一个带有wsdl文件的Ant任务,应该自动生成POJO(客户端Java),所以我可以开始编写客户端JAX-WS Web服务。
但是我收到错误“[ERROR]用于此架构的包名称....不是有效的包名称”
仅当我的 wsdl 文件中包含多个架构导入时才会出现此错误,例如
<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 ,并且只为ANT任务包含1“-p”包命名空间参数,比ANT运行没有错误,但是我的wsdl文件包含多个模式导入。
修改
我更改了“-p”争论的值以遵守包约定,尽管我之前的方法是基于JXC bug论坛。
<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>
我甚至用
尝试了上面的ant任务-p <arg value="${wsdl.mapping.package.request }"/>
<arg value="${wsdl.mapping.package.response}"/>
通过将两个包名称放在由空格分隔的1行上,这是根据JXC doc,解释说您可以使用“按空格分隔的零个或多个包名称空间”。我要求XJC能够处理多个架构导入。
答案 0 :(得分:1)
-p
选项指定单个 Java包,该包应该用于所有生成的类,而不管命名空间如何。如果您希望每个名称空间URI映射到它自己的包,那么您不能使用-p
,而是需要使用绑定自定义文件
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.1">
<bindings schemaLocation="ProcessCustomerInquiryResponse.xsd" node="/xs:schema">
<schemaBindings>
<package name="com.example.inquiry.response"/>
</schemaBindings>
</bindings>
<bindings schemaLocation="ProcessCustomerInquiryRequest.xsd" node="/xs:schema">
<schemaBindings>
<package name="com.example.inquiry.request"/>
</schemaBindings>
</bindings>
</bindings>
并使用xjc
选项
-b
<arg value="-b"/>
<arg file="bindings.xjb"/>
答案 1 :(得分:0)
我认为问题是你的Ant脚本。有两个问题:
<property name="wsdl.mapping.package" value="com.mycompany.xml.generated"/>
此外,还有package per schema approach的链接。
-Muel