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

前端 未结 5 938
我寻月下人不归
我寻月下人不归 2020-12-28 15:25

The Error

I am using wsimport in a Java project to generate sources for three SOAP web services. The first two work fine: I use the JAX-WS Maven plugin to grab the

相关标签:
5条回答
  • 2020-12-28 15:26

    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>
    
    0 讨论(0)
  • 2020-12-28 15:44

    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
    
    0 讨论(0)
  • 2020-12-28 15:48

    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>
    
    0 讨论(0)
  • 2020-12-28 15:48

    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.

    0 讨论(0)
  • 2020-12-28 15:53

    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>
    
    0 讨论(0)
提交回复
热议问题