0

我有一个 wsdl(我没有 .xsd 文件),我想从中生成类。使用 wsimport 我得到一个类树,它是 Web 服务模式本身及其依赖项的标准映射。我得到了 com->(microsoft,mycompany), org->(apache) 之类的东西。

但是我需要将包 com.mycompany 和里面的所有类重新映射到 com.mycompany.test 中。

因此,我尝试使用 ws import 的 -b 选项创建一个 docbinding.xml,即模式自定义 XML。内容是:

<jxb:bindings version="2.1"  xmlns:jxb="http://java.sun.com/xml/ns/jaxb"     xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings node="wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='http://mycompany.com/test/']">
 <jaxb:package name="com.mycompany.test"/>
</jxb:bindings>
</jxb:bindings>

使用以下语法启动 wsimport:

wsimport -p com.mycompany -b docbinding.xml https://mycompany.com/nicews/test.svc?wsdl

我得到一个停止生成类的初始错误:

[ERROR] XPath error: null
...

如何修复绑定 XML?

4

1 回答 1

1

如果类型位于单独的 XSD 文件中。这是做到这一点的方法。

创建两个配置文件。

wsdl.jxb

<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
  wsdlLocation="https://mycompany.com/nicews/test.svc?wsdl"
  xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
    <jaxws:package name="com.mycompany.wsdl"/> <!-- namespace what you want here -->
</jaxws:bindings>

xsds.jxb

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings version="2.1"
           xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
           xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
           xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
           xmlns:xs="http://www.w3.org/2001/XMLSchema" >

    <!-- This is used becuase we don't need to differentiate between absent and nil elements, you may want to differentiate.  If so, remove this binding -->
    <jaxb:globalBindings generateElementProperty="false">
      <xjc:simple />
    </jaxb:globalBindings>  

    <!-- REPEAT THIS SECTION FOR EACH XSD, replacing schemaLocation and package with whatever you want -->
    <jaxb:bindings
           schemaLocation="http://mycompany.com/someWsdlIncludeLocation?xsd=xsd0"
           node="/xs:schema">
          <jaxb:schemaBindings>
        <jaxb:package name="com.mycompany.dto.saml" />
          </jaxb:schemaBindings>
    </jaxb:bindings>
    <!-- END SECTION -->
</jaxb:bindings>

在同一目录下创建批处理文件

rmdir /S /Q build
rmdir /S /Q dist
rmdir /S /Q src
mkdir build
mkdir dist
mkdir src
"%JAVA_HOME%\bin\wsimport.exe" -b wsdl.jxb -b xsds.jxb -s src -d build -keep http://mycompany.com/someWSDLlocation?wsdl
"%java_home%\bin\jar" cf dist/mycompanyClient.jar -C build/ .
"%java_home%\bin\jar" cf dist/mycompanyClient-src.jar -C src/ .

看看这是否适合你。确保为您的 wsdl/xsd 位置和所需的包适当地编辑 JXB 文件。

于 2013-04-03T16:56:48.890 回答