title: How to declare a element for complex data type defined in a xsd file located in jar file
body: <p>I have a below xsd file in a jar dependency file in a Spring boot project. The xsd does not declare the element declaration, which is required by spring boot validation. So I am trying to add another xsd in my project resource folder to declare element type.</p>
  <p><strong>XSD in Jar file:</strong> /wsdl/xsd/UserService-v1-0.xsd</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  
  &lt;xsd:schema targetNamespace=&quot;http://usermanagement.com/userservice/xsd/2014/07&quot;
              xmlns=&quot;http://www.w3.org/2001/XMLSchema&quot;
              xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;
              xmlns:userservice=&quot;http://usermanagement.com/userservice/xsd/2014/07&quot;
              
              elementFormDefault=&quot;qualified&quot;&gt;
  
    &lt;xsd:import namespace=&quot;http://usermanagement.com/userservice/common/xsd/2014/09&quot; schemaLocation=&quot;userserviceCommon-v1-0.xsd&quot;/&gt;
    &lt;xsd:import namespace=&quot;http://usermanagement.com/userserviceabsolute/common/xsd/2014/09&quot; schemaLocation=&quot;userserviceAbsoluteCommon-v1-0.xsd&quot;/&gt;
  
   
    &lt;xsd:complexType name=&quot;GetUsersRequest&quot;&gt;
      &lt;xsd:attribute name=&quot;language&quot; type=&quot;xsd:language&quot; use=&quot;optional&quot; default=&quot;en&quot; /&gt;
    &lt;/xsd:complexType&gt;
  
  &lt;/xsd:schema&gt;
  </code></pre>
  <p>Please note that I tried to keep the complex type simple by removing some of the elements for this post. The location of file is /wsdl/xsd.</p>
  <p><strong>XSD to declare the element in the main Project resource:</strong> /wsdl/xsd/UserService-type-v1-0.xsd</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  
  &lt;xsd:schema targetNamespace=&quot;http://usermanagement.com/userservice/wsdl/userserviceService-v1-0&quot;
    xmlns=&quot;http://www.w3.org/2001/XMLSchema&quot;
    xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;
    xmlns:userservice=&quot;http://usermanagement.com/userservice/xsd/2014/07&quot;
    elementFormDefault=&quot;qualified&quot;&gt;
  
      &lt;import namespace=&quot;http://usermanagement.com/userservice/xsd/2014/07&quot; schemaLocation=&quot;jar:file://{path to the jar}/!/wsdl/xsd/userserviceService-v1-0.xsd&quot;/&gt;
  
  
    &lt;element name=&quot;GetUsersRequest&quot; type=&quot;userservice:GetUsersRequest&quot;/&gt;
  
  &lt;/xsd:schema&gt;
  </code></pre>
  <p>As per my understanding we need to refer to the schemaLocation of xsd file in jar using notation &quot;jar:file://{path to the jar}/!/wsdl/xsd/userserviceService-v1-0.xsd&quot;.
  However I am not sure how to declare the path to the jar. Also not sure if this is the only way to refer to the definitions in the xsd in the jar files. In the above approach when ever a new version of jar is released we need to update the xsd file.</p>
  <p>Also including the Spring WS schema validation config:</p>
  <pre><code>@Configuration
  public class MyWsValidatorConfig extends WsConfigurerAdapter {
  
      @Override
      public void addInterceptors(List&lt;EndpointInterceptor&gt; interceptors) {
          PayloadValidatingInterceptor validatingInterceptor = new PayloadValidatingInterceptor();
          validatingInterceptor.setValidateRequest(true);
          validatingInterceptor.setValidateResponse(true);
          validatingInterceptor.setXsdSchemaCollection(new XsdSchemaCollection() {
              @Override
              public XsdSchema[] getXsdSchemas() {
                  return null;
              }
  
              @Override
              public XmlValidator createValidator() {
                  try {
                      return XmlValidatorFactory.createValidator(getSchemas(), &quot;http://www.w3.org/2001/XMLSchema&quot;);
                  } catch (Exception e) {
                      log.error(&quot;Failed to create validator e={}&quot;, e);
                  }
                  return null;
              }
  
              public Resource[] getSchemas() {
                  List&lt;Resource&gt; schemaResources = new ArrayList&lt;&gt;();
                  schemaResources.add(new ClassPathResource(&quot;/wsdl/xsd/UserService-v1-0.xsd&quot;));
                  schemaResources.add(new ClassPathResource(&quot;/wsdl/xsd/UserService-type-v1-0.xsd&quot;));
                  return schemaResources.toArray(new Resource[schemaResources.size()]);
              }
          });
          interceptors.add(validatingInterceptor);
      }
  
  }
  </code></pre>
  <p>This is the first time I am working with XSD and SOAP web services. Able to cross other hurdles but got stuck with this issue.</p>
  <p>Please help.</p>