如何解决无法使用Maven从WSDL URL或WSDL文件生成源文件?
我有这个link。我需要从那里生成源代码文件。我尝试了两种方法。
Apporach 1
:
在Spring Boot项目中使用Maven工具。这是我的pom.xml
的一部分:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>com.nicordesigns.soapclient</generatePackage>
<schemas>
<schema>
<url>https://clienttesthorizon.horizonafs.com/AFSServices/AFSService.svc?wsdl</url>
</schema>
</schemas>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
错误:
[INFO] --- maven-jaxb2-plugin:0.14.0:generate (default) @ udemy-soap-client ---
[WARNING] The URI [https://clienttesthorizon.horizonafs.com/AFSServices/AFSService.svc?wsdl] seems to represent an absolute HTTP or HTTPS URL. Getting the last modification timestamp is only possible if the URL is accessible and if the server returns the [Last-Modified] header correctly. This method is not reliable and is likely to fail. In this case the last modification timestamp will be assumed to be unknown.
[ERROR] Could not retrieve the last modification timestamp for the URI [https://clienttesthorizon.horizonafs.com/AFSServices/AFSService.svc?wsdl] from the HTTP URL connection. The [Last-Modified] header was probably not set correctly.
[WARNING] Last modification of the URI [https://clienttesthorizon.horizonafs.com/AFSServices/AFSService.svc?wsdl] is not known.
[INFO] Sources are not up-to-date,XJC will be executed.
[ERROR] Error while generating code.Location [ https://clienttesthorizon.horizonafs.com/AFSServices/AFSService.svc?xsd=xsd2{1,20728}].
com.sun.istack.SAXParseException2; systemId: https://clienttesthorizon.horizonafs.com/AFSServices/AFSService.svc?xsd=xsd2; lineNumber: 1; columnNumber: 20728; Two declarations cause a collision in the ObjectFactory class.
at com.sun.tools.xjc.ErrorReceiver.error(ErrorReceiver.java:86)
at com.sun.tools.xjc.generator.bean.ObjectFactoryGeneratorImpl.populate(ObjectFactoryGeneratorImpl.java:191)
通过这种方法,我应该在项目结构的target/generated-source
下获得生成的源代码文件。但是我什么都没得到。我签入文件系统,什么都没有。
Approach 2
:
通过使用wsimport
工具,我试图生成源代码文件:
命令如下:
C:\Users\Miljan\Desktop\WorkspaceSTS\udemy-soap-client>wsimport -keep https://clienttesthorizon.horizonafs.com/AFSServices/AFSService.svc?wsdl
错误:
[WARNING] schema_reference: Failed to read schema document 'AFSService.svc?xsd=xsd0',because 'https' access is not allowed due to restriction set by the accessExternalSchema property.
line 1 of https://clienttesthorizon.horizonafs.com/AFSServices/AFSService.svc?wsdl#types?schema1
[ERROR] Two declarations cause a collision in the ObjectFactory class.
line 1 of https://clienttesthorizon.horizonafs.com/AFSServices/AFSService.svc?xsd=xsd2
[ERROR] (Related to above error) This is the other declaration.
line 1 of https://clienttesthorizon.horizonafs.com/AFSServices/AFSService.svc?xsd=xsd2
Exception in thread "main" com.sun.tools.internal.ws.wscompile.AbortException
at com.sun.tools.internal.ws.processor.modeler.wsdl.JAXBModelBuilder.bind(JAXBModelBuilder.java:129)
at com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.buildJAXBModel(WSDLModeler.java:2283)
at com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.internalBuildModel(WSDLModeler.java:183)
at com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.buildModel(WSDLModeler.java:126)
at com.sun.tools.internal.ws.wscompile.WsimportTool.buildWsdlModel(WsimportTool.java:429)
at com.sun.tools.internal.ws.wscompile.WsimportTool.run(WsimportTool.java:190)
at com.sun.tools.internal.ws.wscompile.WsimportTool.run(WsimportTool.java:168)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.tools.internal.ws.Invoker.invoke(Invoker.java:159)
at com.sun.tools.internal.ws.WsImport.main(WsImport.java:42)
我还在SO的某处(该帖子写于2015年)上读到,为了使wsimport
访问在线.wsdl文件,我需要将jaxp.properties
中的C:\Program Files\Java\jdk1.8.0_261\jre\lib
文件添加到javax.xml.accessExternalSchema = all
中其中的行:
.wsdl
这也重现了错误2。
通常所有从.xsd
或setup
获取这些源文件的帖子都是较早的日期。
解决方法
感谢您提供问题中的完整图片! 以下答案几乎就是此处给出的答案:https://stackoverflow.com/a/13438253/618156
这个问题主要是由于 XJC 在 AccountInfo
和 AFSInvoiceAccountInfo
上有问题(根据上面链接的答案)。
所以似乎需要手动识别它们:
您需要 bindings.xjb
中的以下 src/main/resources
文件(将由 maven-xjb2-plugin
自动找到):
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">
<jaxb:bindings schemaLocation="https://clienttesthorizon.horizonafs.com/AFSServices/AFSService.svc?xsd=xsd2">
<jaxb:bindings node="//xs:element[@name='AFSInvoiceAccountInfo']">
<jaxb:factoryMethod name="AFSInvoiceAccountInfo"/>
</jaxb:bindings>
<jaxb:bindings node="//xs:element[@name='AccountInfo']">
<jaxb:factoryMethod name="AccountInfo"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
...它对我有用,对 maven-xjb2-plugin
中的 pom.xml
进行了以下配置(删除了我认为不需要进行测试的所有内容,它与您最初在问题中发布的内容非常接近):
<project...>
<!-- ... -->
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<schemas>
<schema>
<url>https://clienttesthorizon.horizonafs.com/AFSServices/AFSService.svc?wsdl</url>
</schema>
</schemas>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- ... -->
</plugins>
</build>
</project>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。