Nei*_*ill 5 xpath maven-jaxb2-plugin
我正在尝试使用WSDL并使用maven-jaxb2-plugin生成绑定类.
WSDL是这样的,
<wsdl:definitions>
<wsdl:types>
...
</wsdl:types>
...
<wsdl:message name="IServiceWeb_GetPaymentInfo_InputMessage">
<wsdl:part name="parameters" element="tns:GetPaymentInfo"/>
</wsdl:message>
...
<wsdl:portType name="IServiceWeb">
...
<wsdl:operation name="GetPaymentInfo">
<wsdl:input wsaw:Action="*****" message="tns:IServiceWeb_GetPaymentInfo_InputMessage"/>
<wsdl:output wsaw:Action="*****" message="tns:IServiceWeb_GetPaymentInfo_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
Run Code Online (Sandbox Code Playgroud)
当我最初尝试生成类时,我收到此错误,
org.xml.sax.SAXParseException: A class/interface with the same name "org.package.GetPaymentInfoResponse" is already in use. Use a class customization to resolve this conflict.
Run Code Online (Sandbox Code Playgroud)
我在这个内容中添加了binding.xjb文件,
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:schemaLocation=" http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" version="2.1">
<bindings
node="wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_OutputMessage']/wsdl:part[@name='parameters']">
<class name="GetPaymentInfoOutputMessage" />
</bindings>
</bindings>
Run Code Online (Sandbox Code Playgroud)
而我得到的错误是,
com.sun.istack.SAXParseException2: XPath evaluation of "wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_OutputMessage']/wsdl:part[@name='parameters']" results in empty target node
Run Code Online (Sandbox Code Playgroud)
是否有任何建议来生成这些文件?
编辑 我声明了错误的节点,IServiceWeb_GetPaymentInfo_InputMessage应该是IServiceWeb_GetPaymentInfo_InputMessage,修正后的绑定是,
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:schemaLocation=" http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" version="2.1">
<bindings
node="wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_InputMessage']/wsdl:part[@name='parameters']">
<class name="GetPaymentInfoOutputMessage" />
</bindings>
</bindings>
Run Code Online (Sandbox Code Playgroud)
并且错误消息是,
com.sun.istack.SAXParseException2: XPath evaluation of "wsdl:definitions/wsdl:message[@name='IServiceWeb_GetPaymentInfo_InputMessage']/wsdl:part[@name='parameters']" results in empty target node
Run Code Online (Sandbox Code Playgroud)
解决了
我的绑定文件缺少 schemaLocation 属性,该属性给出了特定 XSD 的导入值(如此处所示)以及我的特定架构的正确 XPath 表达式,
<bindings schemaLocation="https://myURI/mySchema.xsd">
<bindings
node="//xs:complexType[@name='GetPaymentInfoResponse']">
<class name="GetPaymentInfoResponseType" />
</bindings>
</bindings>
Run Code Online (Sandbox Code Playgroud)
此外,使用 JDK 1.6,我需要 d/l 并将 jaxb 2.2 jar 添加到我的 jdk 认可的 lib 目录,如此处所述,http://cxf.apache.org/docs/23-migration-guide.html
使用两种替代方法 {JAVA_HOME}/bin/wsimport.exe 或使用 jaxws-maven-plugin 中的任何一种都会导致“使用类自定义来解决此冲突”错误,该错误已使用此配置解决,
<configuration>
<args>
<arg>-B-XautoNameResolution</arg>
</args>
</configuration>
Run Code Online (Sandbox Code Playgroud)
但不会与上面认可的罐子一起运行。
这样,我的类就生成了,现在可以开始使用 Web 服务了。Maven 是生成类文件的好方法。
| 归档时间: |
|
| 查看次数: |
8487 次 |
| 最近记录: |