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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18898261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 12:05:44  来源:igfitidea点击:

undefined element declaration 'xs:schema'

javaweb-serviceswsdlwsdl2javawsimport

提问by A Nigdikar

I am completely new to web service stuff.

我对网络服务的东西完全陌生。

I have to write rest web service client for a web service. The web service runs fine on SoapUI. WSDL file for the URL is provided to me. But when I add the wsdl file in my Eclipse project, it gives compilation error

我必须为网络服务编写休息网络服务客户端。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'.

I googled a lot to get rid of these error but nothing worked. If I ignore the errors and try creating stubs using wsimport as well as wsdl2java commands it gives error

我用谷歌搜索了很多来摆脱这些错误,但没有任何效果。如果我忽略错误并尝试使用 wsimport 和 wsdl2java 命令创建存根,则会出现错误

[ERROR] undefined element declaration 'xs:schema'
line 1 of http://chec.local/STAR.WCF/CorpsiteService.svc?singlewsdl

I am using below command to generate stubs

我使用下面的命令来生成存根

wsimport -d e:\test -s E:\wssrc http://chec.local/STAR.WCF/CorpsiteService.svc?singlewsdl -wsdllocation "../../../../../WEB-INF/wsdl/CorpsiteService.svc.wsdl"

I am stuck at this point and have been struggling on to this the whole day. Any help regarding this would be really helpful

我被困在这一点上,并且一整天都在为此而苦苦挣扎。任何有关这方面的帮助都会非常有帮助

回答by A Nigdikar

The solution to this appears to be supply alternate bindings for xs:schemaas described in https://metro.java.net/2.1/guide/Dealing_with_schemas_that_are_not_referenced.html

对此的解决方案似乎是为https://metro.java.net/2.1/guide/Dealing_with_schemas_that_are_not_referenced.html 中xs:schema所述提供替代绑定

Specifically, for the http://www.w3.org/2001/XMLSchemawhich is often imported into the namespace xs, there is some additional work that needs to be done.

具体来说,对于经常导入命名空间的http://www.w3.org/2001/XMLSchemaxs,还有一些额外的工作需要完成。

The command would be: wsimport -b http://www.w3.org/2001/XMLSchema.xsd-b customization.xjb something.wsdl

命令将是: wsimport -b http://www.w3.org/2001/XMLSchema.xsd-b customization.xjb something.wsdl

customization.xjb linked from the above is at https://www.java.net//blog/kohsuke/archive/20070228/xsd.xjbor copied from below

从上面链接的customization.xjb 位于https://www.java.net//blog/kohsuke/archive/20070228/xsd.xjb或从下面复制

This customization exists to handle some naming conflicts that might arise from using the schema Schema (which is imported as the same name space in multiple schemas).

此自定义的存在是为了处理使用模式 Schema(在多个模式中作为相同的名称空间导入)可能引起的一些命名冲突。

customization.xjb

定制.xjb

<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
          xmlns:xsd="http://www.w3.org/2001/XMLSchema"
          xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
          version="2.0">

  <globalBindings>
    <xjc:simple />
  </globalBindings>

  <bindings scd="~xsd:complexType">
    <class name="ComplexTypeType"/>
  </bindings>

  <bindings scd="~xsd:simpleType">
    <class name="SimpleTypeType"/>
  </bindings>

  <bindings scd="~xsd:group">
    <class name="GroupType"/>
  </bindings>

  <bindings scd="~xsd:attributeGroup">
    <class name="AttributeGroupType"/>
  </bindings>

  <bindings scd="~xsd:element">
    <class name="ElementType"/>
  </bindings>

  <bindings scd="~xsd:attribute">
    <class name="attributeType"/>
  </bindings>
</bindings>

I have tried this with these files and the associated -bparameters to wsimportand have gotten (apparently) past this error (and on to other ones). That said, I'm not 100% certain that my new errors are not in part caused by this (and thus this wouldn't be a complete answer). Without the actual wsdl causing the problem, one can only take a reasonable guess as to solving the problem (and on to the next one).

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

回答by Gulfam Suleman

I was facing same issue, resolved by just adding one line into maven plugin

我遇到了同样的问题,只需在 maven 插件中添加一行即可解决

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

My maven plugin is given below

下面给出了我的 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>

回答by JJ Roman

If you are using maven-jaxb2-plugin instead -b provide needed URL as additional schema in schemas:

如果您使用 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>

You can even save it in resources so it is picked up automatically

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