我有一个wsdl(我没有.xsd文件),我想从中生成类。 使用wsimport我得到一个类树,它是webservice模式本身及其依赖项的标准映射。 我获得了类似com->(microsoft,mycompany),org->(apache)的东西。
但是我需要将com.mycompany包和里面的所有类重新映射到com.mycompany.test。
所以我尝试使用ws import -b选项创建一个docbin Customization XML的docbinding.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?
答案 0 :(得分: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文件。