Unsupported binding namespace ""
Asked Answered
F

1

6

I have a schema for which JAXB is able to generate java classes perfectly every time. I am trying to get hyperjaxb to process the same schema. Towards that end, I downloaded and unzipped the hyperjaxb maven project from this link and then navigated to the root directory using cmd.exe and tested it with the sample data by running mvn clean install to make sure that it works with the example schema. I then replaced the schema.xsd, po.xml, and bindings.xjb files with the full shema that works perfectly in JAXB, including a number of imported namespaces. I then ran mvn clean install again. However, I am getting the following error message:

[ERROR] Error while parsing schema(s).Location [ file:/C:/path/to/src/main/resources/schema.xsd{4,32}].
org.xml.sax.SAXParseException; systemId: file:/C:/path/to/src/main/resources/schema.xsd; 
lineNumber: 4; columnNumber: 32; Unsupported binding namespace "". 
Perhaps you meant "http://annox.dev.java.net"?

In the sample, the schema tag at the top of schema.xsd is:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="1.0">

By contrast, my custom schema uses:

<xs:schema targetNamespace="urn:some-org:v3" xmlns:mif="urn:some-org:v3/mif" xmlns="urn:some-org:v3"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
    xmlns:sdtc="urn:some-org:sdtc" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="1.0">  

Note the xmlns="urn:some-org:v3" in the schema tag in my custom schema. It does not include a qualifier like xmlns:somequalifier="urn:some-org:v3". Is this causing the problem? It works perfectly in JAXB without the qualifier. It would be a major pain to go through the entire namespace and add a qualifier in front of every type.

Alternatively, it may be that the structures defined in the pom.xml for the sample project (in the zip file linked above) are causing the problem. They are different than the basic JAXB tools.

How can I avoid this problem? Perferably without adding a qualifier to every type. There are several thousand lines in my schema.

The following lines of the stack trace might shed light:

[ERROR] Error while parsing schema(s).Location [ file:/C:/path/to/src/main/resources/schema.xsd{4,32}].
org.xml.sax.SAXParseException; systemId: file:/C:/path/to/src/main/resources/schema.xsd; lineNumber: 4; columnNumber: 32; Unsupported binding namespace "". Perhaps you meant "http://annox.dev.java.net"?
    at com.sun.tools.xjc.reader.AbstractExtensionBindingChecker.error(AbstractExtensionBindingChecker.java:213)
    at com.sun.tools.xjc.reader.AbstractExtensionBindingChecker.checkAndEnable(AbstractExtensionBindingChecker.java:115)
    at com.sun.tools.xjc.reader.ExtensionBindingChecker.startElement(ExtensionBindingChecker.java:133)
    at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
    at com.sun.tools.xjc.reader.xmlschema.parser.IncorrectNamespaceURIChecker.startElement(IncorrectNamespaceURIChecker.java:128)
    at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
    at com.sun.tools.xjc.reader.xmlschema.parser.CustomizationContextChecker.startElement(CustomizationContextChecker.java:193)
    at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
    at com.sun.tools.xjc.reader.internalizer.DOMForestScanner$LocationResolver.startElement(DOMForestScanner.java:147)
    at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:244)
    at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:127)
    at com.sun.tools.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:92)
    at com.sun.tools.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:100)
    at com.sun.tools.xjc.reader.internalizer.DOMForestParser.parse(DOMForestParser.java:104)
    at com.sun.tools.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:269)
    at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:347)
    at com.sun.xml.xsom.impl.parser.ParserContext.parse(ParserContext.java:128)
    at com.sun.xml.xsom.parser.XSOMParser.parse(XSOMParser.java:168)
    at com.sun.xml.xsom.parser.XSOMParser.parse(XSOMParser.java:157)
    at com.sun.tools.xjc.ModelLoader.createXSOM(ModelLoader.java:534)
    at com.sun.tools.xjc.ModelLoader.loadXMLSchema(ModelLoader.java:378)
    at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:174)
    at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:119)
    at org.jvnet.mjiip.v_2_2.XJC22Mojo.loadModel(XJC22Mojo.java:50)
    at org.jvnet.mjiip.v_2_2.XJC22Mojo.doExecute(XJC22Mojo.java:40)
    at org.jvnet.mjiip.v_2_2.XJC22Mojo.doExecute(XJC22Mojo.java:28)
    at org.jvnet.jaxb2.maven2.RawXJC2Mojo.doExecute(RawXJC2Mojo.java:318)
    at org.jvnet.jaxb2.maven2.RawXJC2Mojo.execute(RawXJC2Mojo.java:161)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Fireweed answered 16/10, 2014 at 20:59 Comment(5)
Can you add all xsd involved? sorry the question is not really clear to me .Payola
@Payola I uploaded the whole resources directory, including all the xsd, to a zip file. I suspect the codehaus.mojo plugin is the problem, but I am not sure. Here is the link: jumpshare.com/v/QsE0KEFiUV2CyMvneoJ9?b=7JBK9muM8YTIqVmwoItOFireweed
@Payola Do you need an xml file to match the xsd?Fireweed
I'm trying to solve your issue, but for now anything. Anyway, thank you for your good words. :)Payola
I tried using maven-jaxb2-plugin and works fine .. I think that there is some issue on include\urn\namespace for maven-hyperjaxb3-plugin. I validated also the XSD and are all correct. I'll Let you know if i have good news.Payola
P
3

The error that you see is due to missing the prefix on tag <property name="xsid"/>. The correct tag is below

<jaxb:bindings node="//xs:complexType[@name='Section']/xs:attribute[@name='ID']">
    <jaxb:property name="xsid"/>
</jaxb:bindings>

Anyway your XSDs have some problem because by maven-jaxb2-plugin is possible to generates all classes and maven-hyperjaxb3-plugin is not possible.


I suggest a work around for your entire problem. If you don't needed to mark as @Entity or @Table all class that you generated, you could use below configuration.

XJB

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
    version="2.1"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:annox="http://annox.dev.java.net"  >

    <jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
        <jaxb:globalBindings generateIsSetMethod="true"/>
        <jaxb:schemaBindings>
            <jaxb:package name="org.jvnet.hyperjaxb3.ejb.tests.pocustomized"/>
        </jaxb:schemaBindings>
        <jaxb:bindings node="//xs:complexType[@name='InfrastructureRoot.typeId']">
            <annox:annotate>
                <annox:annotate annox:class="javax.persistence.Entity">
                </annox:annotate>
                <annox:annotate annox:class="javax.persistence.Table" name="typeId">
                </annox:annotate>
            </annox:annotate>
        </jaxb:bindings>
        <jaxb:bindings node="//xs:complexType[@name='ObservationMedia']/xs:attribute[@name='ID']">
            <jaxb:property name="xsid"/>
        </jaxb:bindings>
        <jaxb:bindings node="//xs:complexType[@name='RegionOfInterest']/xs:attribute[@name='ID']">
            <jaxb:property name="xsid"/>
        </jaxb:bindings>
        <jaxb:bindings node="//xs:complexType[@name='Section']/xs:attribute[@name='ID']">
            <jaxb:property name="xsid"/>
        </jaxb:bindings>


    </jaxb:bindings>

</jaxb:bindings>

Maven Plugin

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.8.1</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>
    </dependencies>
    <configuration>
        <args>
            <arg>-Xannotate</arg>
            <arg>-nv</arg>
        </args>
        <extension>true</extension>
        <schemaDirectory>src/main/resources/</schemaDirectory>
        <schemaIncludes>
            <schemaInclude>schema.xsd</schemaInclude>
        </schemaIncludes>
        <bindingDirectory>src/main/resources/</bindingDirectory>
        <bindingIncludes>
            <include>*.xjb</include>
        </bindingIncludes>
        <debug>true</debug>
        <verbose>true</verbose>
        <episode>true</episode>
        <forceRegenerate>true</forceRegenerate>
        <plugins>
            <plugin>
                <groupId>org.jvnet.jaxb2_commons</groupId>
                <artifactId>jaxb2-basics</artifactId>
                <version>0.6.3</version>
            </plugin>
            <plugin>
                <groupId>org.jvnet.jaxb2_commons</groupId>
                <artifactId>jaxb2-basics-annotate</artifactId>
                <version>0.6.3</version>
            </plugin>
        </plugins>
    </configuration>
</plugin>

Ain't a best practices but works fine.

Payola answered 17/10, 2014 at 12:42 Comment(4)
Hyperjaxb allows ignoring classes OOTB: confluence.highsource.org/display/HJ3/… Using the annotate plugin will work but has limitations. Some of the generated constructs are not JPA-compatible, Hyperjaxb mostly restructures them. annotate plugin can't do that. See confluence.highsource.org/display/HJ3/…Mozarab
@Payola Thank you very much for looking into this. I deleted the contents of bindings.xjb then I put your content verbatim into bindings.xjb. Next, I added your plugin tag to the pom.xml, to create the pom.xml you can read at this link: jumpshare.com/v/MUvit4oWZqBlPPXFLM1g?b=D09y0Bld0v99GBP7kASX But I am getting the following error log when I try mvn clean install on the root directory of the project: jumpshare.com/v/GpM69nFzhPIgQmAvqJrb?b=D09y0Bld0v99GBP7kASX Did I implement your suggestions correctly?Fireweed
@Payola +1 and thank you for helping me with this. The code you proposed is generating a new error related to setting up the -Xannotate switch. I have posted the new error as a separate question. Are you willing to help me with it also? Here is the link: #26430699Fireweed
@Fireweed I seen your pom.xml, you should only remove maven-hyperjaxb3-plugin to work fine. Let me know.Payola

© 2022 - 2024 — McMap. All rights reserved.