JAX-WS error on WSDL file: “Error resolving component 's:schema'”

依然范特西╮ 提交于 2019-11-30 03:31:40

I solved this by adapting Vivek Pandey's method to Maven, while updating to the jaxws-maven-plugin 2.2. I'll reiterate it here for posterity:

Summary

Put this XJB customization file (see below) in your default binding files directory, and set wsimport to bind it and http://www.w3.org/2001/XMLSchema.xsd .

XJB Customization

The contents of the aforementioned XML file, xsd.xjb, that should go in your default binding files directory, is as follows (credit goes to Kohsuke):

<?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>

POM

Here's the relevant part of my POM file, with changes noted:

<plugin>
    <!-- CHANGE: updated groupId and version -->
    <groupId>org.jvnet.jax-ws-commons</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.2</version>
    <executions>
        <execution> 
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <!-- CHANGE: added args tag to bind http://www.w3.org/2001/XMLSchema.xsd -->
                <args>
                    <arg>-b</arg><arg>http://www.w3.org/2001/XMLSchema.xsd</arg>
                </args>
                <wsdlFiles>
                    <wsdlFile>erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl</wsdlFile>
                </wsdlFiles>
                <wsdlLocation>http://erp-app-devel.srv.mycompany.ca/EgTestReportEngine/Service.asmx.wsdl</wsdlLocation>
                <staleFile>${project.build.directory}/jaxws/stale/Service.asmx.stale</staleFile>
                <!-- CHANGE: added bindingFiles tag to bind XJB customization, located at the default binding files directory, MyProject/src/jaxws/xsd.xjb . -->
                <bindingFiles>
                    <bindingFile>xsd.xjb</bindingFile>
                </bindingFiles>
            </configuration>
            <id>wsimport-generate-egtestreportengine</id>
            <phase>generate-sources</phase>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>javax.xml</groupId>
            <artifactId>webservices-api</artifactId>
            <version>1.4</version>
        </dependency>
    </dependencies>
    <configuration>
        <sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport</sourceDestDir>
        <xnocompile>true</xnocompile>
        <verbose>true</verbose>
        <extension>true</extension>
        <catalog>${basedir}/src/jax-ws-catalog.xml</catalog>
        <target>2.0</target>
    </configuration>
</plugin>

For Nick's solution to work you may have to add these two jvm arguments to your pom.xml So when encountering those errors:

org.xml.sax.SAXParseException; systemId: http://www.w3.org/2001/XMLSchema.xsd; lineNumber: 67; columnNumber: 11; External DTD: Failed to read external DTD 'XMLSchema.dtd', because 'http' access is not allowed due to restriction set by the accessExternalDTD property.

[WARNING] schema_reference: Failed to read schema document 'xml.xsd', because 'http' access is not allowed due to restriction set by the accessExternalSchema property. line 91 of http://www.w3.org/2001/XMLSchema.xsd

Just add those to your pom.xml

-Djavax.xml.accessExternalDTD=all
-Djavax.xml.accessExternalSchema=all

<vmArgs>
    <vmArg>-Djavax.xml.accessExternalDTD=all</vmArg>
    <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
</vmArgs>

If you don't actually care about this particular bit of the model data you might be able to use a JAXB bindings file to tell JAXB to map the offending bits to properties whose type is a DOM Element rather than actually trying to data bind them into normal JAXB classes. The unofficial JAXB guide has a section on this technique.

Had same issue fixed it with below command:

wsimport -b http://www.w3.org/2001/XMLSchema.xsd -b xsd.xjb service.wsdl

where xsd.xjb refers to :

<?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>

This seems to be working for me finally. I am using apache maven cfx plugin

    <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <additionalJvmArgs>
                                -Djavax.xml.accessExternalDTD=all
                            </additionalJvmArgs>
                            <sourceRoot>${basedir}/src/main/generated</sourceRoot> 
                            <wsdlOptions>
                                <wsdlOption>
                                    <extraargs>
                                        <extraarg>-autoNameResolution</extraarg>
                                        <extraarg>-impl</extraarg>
                                        <extraarg>-verbose</extraarg>
                                        <extraarg>-b</extraarg>
                                        <extraarg>http://www.w3.org/2001/XMLSchema.xsd</extraarg>

                                        <extraarg>-p</extraarg>
                                        <extraarg>com.nevado.travelstudio</extraarg>
                                    </extraargs>
                                    <!-- <bindingFiles> <bindingFile>${basedir}/src/main/resources/wsdl/mybindings.xjb</bindingFile> 
                                        </bindingFiles> -->
                                    <wsdl>${basedir}/src/main/resources/wsdl/B2.wsdl</wsdl>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

along with these changes I had to create jaxp.properties file in ..java/jdk/jre/lib folder with following property

  -Djavax.xml.accessExternalDTD=all
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!