Search code examples
mavenpackagejaxb2

Maven Jaxb Generated Package Names Are Backwards


I have created a simple Maven project which uses Jaxb to compile a schema into Java files. Everything seems to be working but the problem is the generated package names are backwards:

Windows Explorer

My Xml schema looks like the following:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://com.mystuff.jaxb.inventorycontrol.inventorydata"
    targetNamespace="http://com.mystuff.jaxb.inventorycontrol.inventorydata" elementFormDefault="qualified" version="1.0.0">
    ....
    ....      
    <xs:complexType name="InventoryItemListType">
        <xs:sequence>
            <xs:element name="Item" type="InventoryItemType" />
        </xs:sequence>
    </xs:complexType>        
</xs:schema>

The namespace http://com.mystuff.jaxb.inventorycontrol.inventorydata starts with com and ends with inventorydata so I thought this would be the package/folder order:

com\mystuff\jaxb\inventorycontrol\inventorydata

but mine ends up backwards:

inventorydata\inventorycontrol\jaxb\mystuff\com\

Not sure if it's overkill to paste some of my pom.xml here but I guess it won't hurt.

Here is my root pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    ....
    <packaging>pom</packaging>
    <groupId>com.mystuff.jaxb</groupId>
    <artifactId>inventorycontrol</artifactId>
    <version>1.0-SNAPSHOT</version>
    ....
    <build>
        <pluginManagement>
            <plugins>
                ....
                <plugin>
                    <groupId>org.jvnet.jaxb2.maven2</groupId>
                    <artifactId>maven-jaxb2-plugin</artifactId>
                    <version>${maven-jaxb2-plugin-version}</version>
                    <configuration>
                        <catalog>src/main/resources/catalog.xml</catalog>
                        <catalogResolver>org.jvnet.jaxb2.maven2.resolver.tools.ClasspathCatalogResolver</catalogResolver>
                        <extension>true</extension>
                        <schemaDirectory>${basedir}/src/main/resources/xsd</schemaDirectory>
                        <schemaIncludes>
                            <include>*.xsd</include>
                        </schemaIncludes>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>    
    </build>

    <modules>
        <module>inventorydata</module>
    </modules>

</project>

And here is the pom for the module that has the schema:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    ....
    <packaging>pom</packaging>
    <parent>
        <groupId>com.mystuff.jaxb</groupId>
        <artifactId>inventorycontrol</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>com.mystuff.jaxb.inventorycontrol</groupId>
    <artifactId>inventorydata</artifactId>
    ....
    <build>
        <plugins>
            ....
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

_UPDATE_

When I created my project I basically copy/pasted the schema/pom files from an old project to this new project. The old projects schema looked like the following:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.cmv.com/java/maven/jaxb/schemas/core/types"
    targetNamespace="http://www.cmv.com/java/maven/jaxb/schemas/core/types" elementFormDefault="qualified" version="1.0.0">
    ....
    <xs:complexType name="PoundsWeightType">
        <xs:sequence>
            <xs:element name="Value" type="PositiveFloat" />
        </xs:sequence>
        <xs:attribute name="Units" type="UnitsEnum" use="required" fixed="Lbs" />
    </xs:complexType>
</xs:schema>    

And my generated package for that project is:

com\cmv\java\maven\jaxb\schemas\core\types

Project With Correct Order

Which is what I would expect.


Solution

  • Java components, packages, etc... are named using reverse dns. You're specifying the namespace in DNS format, meaning, well, that you're meant to reverse it.

    The namespace com.mystuff.jaxb.inventorycontrol.inventorydata, written out as a url would be: http://inventorydata.inventorycontrol.jaxb.mystuff.com