3

I want to generate java classes with the jaxb2-maven-plugin. I am using the following configuration:

pom.xml:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>2.5.0</version>
    <executions>
        <execution>
            <id>SomeID</id>
            <goals>
                <goal>xjc</goal>
            </goals>
            <configuration>
                <extension>true</extension>
                <clearOutputDir>true</clearOutputDir>
                <sources>
                    <source>src/main/xsd/schema.xsd</source>
                </sources>
                <noGeneratedHeaderComments>true</noGeneratedHeaderComments>
            </configuration>
        </execution>
    </executions>
</plugin>

schema.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://my.target.namespace/uri" 
    xmlns="http://my.target.namespace/uri" 
    elementFormDefault="qualified"
    attributeFormDefault="unqualified"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:h="http://my.uri.for.prefix.h"
    xmlns:f="http://my.target.namespace/uri">
    
    <xsd:import namespace="http://my.uri.for.prefix.h" schemaLocation="schema2.xsd"/> 
    
    <xsd:complexType name="FooType">
        <xsd:sequence>
            <xsd:element ref="h:something" minOccurs="0" maxOccurs="1"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:element name="FooType" type="FooType" />
 
</xsd:schema>

The Jaxb2 plugin is generating me the following package-info.java:

@javax.xml.bind.annotation.XmlSchema(namespace = "http://my.target.namespace/uri", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package ...;

But, what I want to get is this:

@javax.xml.bind.annotation.XmlSchema(namespace = "http://my.target.namespace/uri", xmlns = {
        @XmlNs(prefix="f", namespaceURI="http://my.target.namespace/uri"),
        @XmlNs(prefix="h", namespaceURI="http://my.uri.for.prefix.h")
}, elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package ...;

import javax.xml.bind.annotation.XmlNs;

The prefixes are missing in my generated file. How to do that? I tried already to create a binding file but this didn't worked how I expected.

micharaze
  • 814
  • 7
  • 19

0 Answers0