phax / maven-jaxb2-plugin

The most advanced JAXB 2.x/3.0/4.0 Maven Plugin for XML Schema compilation.
BSD 2-Clause "Simplified" License
7 stars 2 forks source link

Warning on Maven Build #10

Closed jeeva-selvam closed 11 months ago

jeeva-selvam commented 1 year ago

Hi @phax , Can you please check the https://github.com/arunnprakash/spring-poc/issues/1 , seem when adding dependency we see some warning on maven build. Is there any ways to skip those ?

phax commented 1 year ago

@jeeva-selvam this seems to be an error in JAXB. As it is mentioned to be an "experimental" feature I suggest you don't use it. My recommendation would be to manually extract the XML Schema part from the WSDL and compile it separately. hth

jeeva-selvam commented 1 year ago

@phax java17 is used with springboot 3.0.2, so why should be the recommended version for jaxb ? It would be much helpful if you kindly share the supported details for it, as I'm completely new in handling wsdl and xsd's binding.xml is also used

phax commented 1 year ago

Maybe I have misunderstood the question. In the issue you linked, you show a list of errors:

  1. org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw 'Adds two integers. This is a test WebService. ©DNE Online'.
  2. org.xml.sax.SAXParseException: s4s-elt-schema-ns: The namespace of element 'definitions' must be from the schema namespace, 'http://www.w3.org/2001/XMLSchema'.
  3. Error while parsing schema(s).Location [ file:/Users//Documents/express/codebase/test/spring-poc/maven-poc-jaxb2/src/main/resources/wsdl/sample.wsdl{2,500}]. org.xml.sax.SAXParseException: s4s-elt-invalid: Element 'definitions' is not a valid element in a schema document.
  4. org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'file:/Users/**/Documents/express/codebase/test/spring-poc/maven-poc-jaxb2/src/main/resources/wsdl/sample.wsdl', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not xsd:schema.

This is independent of Java 17 etc. What you are trying to do, is to create the Java domain model from the XML Schema that is contained in your WSDL file: https://github.com/arunnprakash/spring-poc/blob/main/maven-poc-jaxb2/src/main/resources/wsdl/sample.wsdl#L4-L65

JAXB is the Java technology for doing this, and since Java 9 or so, this is no longer part of the runtime but a separate module. Currenly Eclipse Jakarta is the maintainer of the JAXB technology.

So instead of compiling the XSD inside the WSDL, I suggest to extract the XML Schema part into a separate file (e.g. "sample.xsd") and "xs:include" the file into the WSDL (please google how to do it). For the JAXB plugin you only reference the "sample.xsd" file and NOT the WSDL (just remove the <language> configuration item in the POM).

The binding file is used to customize the code creation. The catalog file is used to resolve dependencies from other repositories - that is advanced stuff I would say.

See the following example for an XML Schema that is called "Standard Business Document Header":

  1. pom.xml to compile the sources: https://github.com/phax/ph-sbdh/blob/master/pom.xml#L145 (variables are declared above). Strip some customizations so that the result looks like this:
      <plugin>
        <groupId>${jaxb-plugin.group}</groupId>
        <artifactId>${jaxb-plugin.artifact}</artifactId>
        <version>${jaxb-plugin.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <generateDirectory>${project.build.directory}/generated-sources/sbdh</generateDirectory>
              <schemaDirectory>${basedir}/src/main/resources/schemas/sbdh</schemaDirectory>
              <schemaIncludes>
                <schemaInclude>StandardBusinessDocumentHeader.xsd</schemaInclude>
              </schemaIncludes>
              <bindingIncludes>
                <bindingInclude>bindings.xjb</bindingInclude>
              </bindingIncludes>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <bindingDirectory>${basedir}/src/main/jaxb</bindingDirectory>
          <extension>true</extension>
        </configuration>
      </plugin>
  2. The binding file can be found at: https://github.com/phax/ph-sbdh/blob/master/src/main/jaxb/bindings.xjb - please note that lines 26 to 30 are irrelevant for you
  3. This configuration does not include a catalog file

hth