无法使用Maven从WSDL URL或WSDL文件生成源文件?

如何解决无法使用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。

通常所有从.xsdsetup获取这些源文件的帖子都是较早的日期。

解决方法

感谢您提供问题中的完整图片! 以下答案几乎就是此处给出的答案:https://stackoverflow.com/a/13438253/618156

这个问题主要是由于 XJC 在 AccountInfoAFSInvoiceAccountInfo 上有问题(根据上面链接的答案)。

所以似乎需要手动识别它们:

您需要 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 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-