Java 未定义的元素声明';xs:schema';

Java 未定义的元素声明';xs:schema';,java,web-services,wsdl,wsdl2java,wsimport,Java,Web Services,Wsdl,Wsdl2java,Wsimport,我对web服务完全陌生 我必须为web服务编写RESTWeb服务客户端。web服务在SoapUI上运行良好。URL的WSDL文件已提供给我。但是,当我在Eclipse项目中添加wsdl文件时,它给出了编译错误 src-resolve.4.2: Error resolving component 'xs:schema'. It was detected that 'xs:schema' is in namespace 'http://www.w3.org/2001/XMLSchema', but

我对web服务完全陌生

我必须为web服务编写RESTWeb服务客户端。web服务在SoapUI上运行良好。URL的WSDL文件已提供给我。但是,当我在Eclipse项目中添加wsdl文件时,它给出了编译错误

src-resolve.4.2: Error resolving component 'xs:schema'. It was detected that 'xs:schema' is in namespace 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document 'file:///E:/Ashish%20Workspace/HATStoLSAMS%20Webservice/HATS2LSAMSWS/WebContent/WEB-INF/wsdl/CorpsiteService.svc.wsdl'. If this is the incorrect namespace, perhaps the prefix of 'xs:schema' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'file:///E:/Ashish%20Workspace/HATStoLSAMS%20Webservice/HATS2LSAMSWS/WebContent/WEB-INF/wsdl/CorpsiteService.svc.wsdl'.
为了消除这些错误,我在谷歌上搜索了很多次,但什么也没用。 如果忽略错误并尝试使用wsimport和wsdl2java命令创建存根 这是错误的

[ERROR] undefined element declaration 'xs:schema'
line 1 of http://chec.local/STAR.WCF/CorpsiteService.svc?singlewsdl
我正在使用下面的命令生成存根

wsimport -d e:\test -s E:\wssrc http://chec.local/STAR.WCF/CorpsiteService.svc?singlewsdl -wsdllocation "../../../../../WEB-INF/wsdl/CorpsiteService.svc.wsdl"
我被困在这一点上,为此奋斗了一整天。
关于这方面的任何帮助都非常有用

解决方案似乎是为
xs:schema
提供替代绑定,如中所述

具体来说,对于经常导入到命名空间
xs
中的,还需要做一些额外的工作

命令应该是:
wsimport-b-b customization.xjb something.wsdl

从上面链接的customization.xjb位于或从下面复制

此自定义用于处理使用模式(在多个模式中作为相同名称空间导入)可能产生的一些命名冲突

customization.xjb



我用这些文件和与
wsimport
相关的
-b
参数尝试了这一点,并且(显然)已经克服了这个错误(并转到了其他错误)。也就是说,我不能100%确定我的新错误是否部分是由此引起的(因此这不是一个完整的答案)。如果没有实际的wsdl导致问题,我们只能对解决问题(以及下一个问题)进行合理的猜测。

我也面临同样的问题,只需在maven插件中添加一行代码即可解决

<args> 
    <arg>-b</arg>
    <arg>http://www.w3.org/2001/XMLSchema.xsd</arg>
</args>

-b
http://www.w3.org/2001/XMLSchema.xsd
下面给出了我的maven插件

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.4.1</version>
    <executions>
        <execution>
            <id>periodictableaccessws</id>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory>
                <args>
                    <arg>-b</arg>
                    <arg>http://www.w3.org/2001/XMLSchema.xsd</arg>
                </args>
                <wsdlFiles>
                    <wsdlFile>doosdaas.wsdl</wsdlFile>
                </wsdlFiles>
                <packageName>com.dss.doosdaas</packageName>
                <vmArgs>
                    <vmArg>-Djavax.xml.accessExternalDTD=all</vmArg>
                    <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
                </vmArgs>
                <!--   <bindingDirectory>${basedir}/src/main/resources/jaxb</bindingDirectory>
                   <bindingFiles>
                       <bindingFile>jaxb_binding.xjb</bindingFile>
                   </bindingFiles>-->
            </configuration>
        </execution>
    </executions>
</plugin>

org.codehaus.mojo
jaxws-maven插件
2.4.1
周期表存取
wsimport
${basedir}/src/main/resources/wsdl
-b
http://www.w3.org/2001/XMLSchema.xsd
doosdaas.wsdl
com.dss.doosdaas
-Djavax.xml.accessExternalDTD=all
-Djavax.xml.accessExternalSchema=all

如果您使用的是maven-jaxb2-plugin-b,请在模式中提供所需的URL作为附加模式:

<schema>
  <url>https://example.com/WebService.asmx?WSDL</url>
</schema>
<schema>
  <url>http://www.w3.org/2001/XMLSchema.xsd</url>
</schema>

https://example.com/WebService.asmx?WSDL
http://www.w3.org/2001/XMLSchema.xsd

您甚至可以将其保存在资源中,以便自动拾取它

当我不得不使用一些UE Taxations Customs web服务时,我会遇到这种错误。在以前的项目中,我使用了

但对于最近的项目,我使用了另一个同样基于绑定但更短的解决方案,我使用了这里描述的包装器样式规则

1-创建包含以下内容的绑定文件,并将其添加到META-INF文件夹:

<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
    <jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
</jaxws:bindings>

假的
2-使用wsimport从wsdl创建Web服务引用(在我的示例中,我使用在后台使用wsimport的Netbeans IDE WS客户端助手),例如:

注意:首先,wsimport的过程可能是raise和error或not,但添加或不添加前一个绑定的区别很容易检查

3-将绑定引用添加到.pom文件中相应的jaxws maven插件执行。例如,它保持如下状态:

<plugin>
    <groupId>org.jvnet.jax-ws-commons</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <wsdlFiles>
                    <wsdlFile>ec.europa.eu/taxation_customs/tin/checkTinService.wsdl</wsdlFile>
                </wsdlFiles>
                <packageName></packageName>
                <vmArgs>
                    <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
                </vmArgs>
                <wsdlLocation>https://ec.europa.eu/taxation_customs/tin/checkTinService.wsdl</wsdlLocation>
                <staleFile>${project.build.directory}/jaxws/stale/checkTinService.stale</staleFile>
                <bindingFiles>
                    <bindingFile>${basedir}/src/main/resources/META-INF/TaxationCustomsWsImportBindings.xml</bindingFile>
                </bindingFiles>
            </configuration>
            <id>wsimport-generate-checkTinService</id>
            <phase>generate-sources</phase>
        </execution>
    </executions>
    ...

org.jvnet.jax-ws-commons
jaxws-maven插件
2.3
wsimport
ec.europa.eu/taxing_customs/tin/checkTinService.wsdl
-Djavax.xml.accessExternalSchema=all
https://ec.europa.eu/taxation_customs/tin/checkTinService.wsdl
${project.build.directory}/jaxws/stale/checkTinService.stale
${basedir}/src/main/resources/META-INF/TaxationCustomsWsImportBindings.xml
wsimport生成checkTinService
生成源
...
您可以看到使用之前创建的绑定文件的确切配置:

<bindingFiles>
       <bindingFile>${basedir}/src/main/resources/META-INF/TaxationCustomsWsImportBindings.xml</bindingFile>
</bindingFiles>

${basedir}/src/main/resources/META-INF/TaxationCustomsWsImportBindings.xml

4-最后转到“刷新de WS参考”,更改将应用于wsimport过程。

感谢@MichaelT提供的简明答案和提供的链接,为我解决了问题。@jlr感谢您让我知道它很有用。有了xsd,我永远无法解决这些错误,转而使用ApacheAxis库来完成客户机中更加宽容/动态的工作。也就是说,它的客户端更具动态性,没有wsimport提供的简单静态类型。我没有使用
wsimport
而是使用apachecxf的
wsdl2java
工具来生成这些类型。我远离Glassfish,因为我在过去遇到过一些与它无关的问题(关于定制数据序列化,无论我怎么做都无法工作,CXF是开箱即用的!)。