While migrating a service to java21 and jaxb3.0, the class generation for xjb file from a wsdl is giving a 'org.xml.sax.SAXParseException; XXX The prefix "jxb" for element "jxb:bindings" is not bound.' Not sure if the problem is the file it self or the way the plugin is configured.
The final error for the maven build is: [ERROR] Failed to execute goal org.jvnet.jaxb:jaxb-maven-plugin:4.0.0:generate (WSDL) on project project-api: Unable to parse input schema(s). Error messages should have been provided. -> [Help 1]
The cause of the exception is the class generation by the plugin. Main exception: [ERROR] Error while parsing schema(s).Location [ file:/C:/project/project-api/src/main/resources/bindings/wsBinding.xjb{8,52}]. org.xml.sax.SAXParseException: The prefix "jxb" for element "jxb:bindings" is not bound. ... (long stacktrace)
following the exception: org.xml.sax.SAXParseException; systemId: file:/C:/project/project-api/src/main/resources/bindings/wsBinding.xjb; lineNumber: 8; columnNumber: 52; The prefix "jxb" for element "jxb:bindings" is not bound. ... (more stacktrace)
Here are the binding in question:
original bindings (jaxb2, java8):
<?xml version="1.0" encoding="UTF-8"?>
<jxb:bindings version="1.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:annox="http://annox.dev.java.net"
jxb:extensionBindingPrefixes="annox">
<jxb:globalBindings>
<xjc:serializable uid="7702"/>
<xjc:javaType adapter="com.cie.project.adapter.LocalDateAdapter" name="java.time.LocalDate"
xmlType="xsd:date"/>
</jxb:globalBindings>
<jxb:bindings schemaLocation="../clients/wsBinding.wsdl" node="/wsdl:definitions/wsdl:types/xsd:schema">
<jxb:bindings node="//xsd:complexType[@name='theRequest']">
<jxb:class name="TheRequestType"/>
<annox:annotateClass>@javax.xml.bind.annotation.XmlRootElement(name="theRequest")</annox:annotateClass>
</jxb:bindings>
<jxb:bindings node="//xsd:complexType[@name='theResponse']">
<jxb:class name="TheResponseType"/>
<annox:annotateClass>@javax.xml.bind.annotation.XmlRootElement(name="theResponse")</annox:annotateClass>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
new updated binding with the error (java21, jaxb3)
<?xml version="1.0" encoding="UTF-8"?>
<jxb:bindings version="1.0"
xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:annox="http://annox.dev.java.net"
jxb:extensionBindingPrefixes="annox">
<jxb:globalBindings>
<xjc:serializable uid="7702"/>
<xjc:javaType adapter="com.cie.project.adapter.LocalDateAdapter" name="java.time.LocalDate"
xmlType="xsd:date"/>
</jxb:globalBindings>
<jxb:bindings schemaLocation="../clients/wsBinding.wsdl" node="/wsdl:definitions/wsdl:types/xsd:schema">
<jxb:bindings node="//xsd:complexType[@name='theRequest']">
<jxb:class name="TheRequestType"/>
<annox:annotateClass>@jakarta.xml.bind.annotation.XmlRootElement(name="theRequest")</annox:annotateClass>
</jxb:bindings>
<jxb:bindings node="//xsd:complexType[@name='theResponse']">
<jxb:class name="TheResponseType"/>
<annox:annotateClass>@jakarta.xml.bind.annotation.XmlRootElement(name="theResponse")</annox:annotateClass>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
Here the jaxbplugin config in maven if it could help
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin</artifactId>
<executions>
<execution>
<id>WSDL</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>com.cie.project.ws</generatePackage>
<schemaDirectory>${project.basedir}</schemaDirectory>
<schemaIncludes>
<include>src/main/resources/clients/*.wsdl</include>
</schemaIncludes>
<bindingDirectory>${project.basedir}</bindingDirectory>
<bindingIncludes>
<include>src/main/resources/bindings/*.xjb</include>
</bindingIncludes>
<verbose>true</verbose>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugins</artifactId>
</plugin>
</plugins>
</configuration>
</plugin>
Note sure if this is related I got a weird warning before these exception: org.xml.sax.SAXParseException: Are you trying to compile a WSDL ? Support for WSDL is experimental. You may enable it by using the -wsdl option.
EDIT: Answer:
The header for the binding file need to be updated from xmlns:jaxb to xmlns:jxb (from @Laurent Schoelens answer) and need to be version 3.
<jxb:bindings version="3.0"
xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:annox="urn:jaxb.jvnet.org:annox"
jxb:extensionBindingPrefixes="annox">
Not sure if it related but the plugin needed to include the following plugin to work:
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-basics-annotate</artifactId>
<version>2.0.9</version>
Your binding has a simple error :
<jxb:bindings version="3.0"
xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:annox="http://annox.dev.java.net"
jxb:extensionBindingPrefixes="annox">
You got jxb:bindings
declaration but xmlns:jAxb
as declared namespace.
If you still want to use jxb, replace xmlns:jaxb
with xmlns:jxb
namespace prefix.
And you can also replace the xmlns:annox="http://annox.dev.java.net"
with the new annox namespace urn:jaxb.jvnet.org:annox
(so with xmlns:annox="urn:jaxb.jvnet.org:annox"
). See plugin's migration guide