0

我有一个 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.xsdrequest.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 个模式导入。

4

2 回答 2

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"/>
于 2012-10-30T23:31:28.757 回答
0

我认为问题出在您的 Ant 脚本上。有两个问题:

  1. package 属性的值必须是 java 包。例如:<property name="wsdl.mapping.package" value="com.mycompany.xml.generated"/>
  2. 您应该只指定一个包而不是两个。

祝你好运!

此外,这里是每个模式方法的包的链接。

-穆尔

于 2012-10-30T23:19:27.717 回答