views:

137

answers:

1

Hello!

I am trying to generate java source files from a package of *.xsd files using the xjc code generation tool.

The namespaces used in those *.xsd files are as follows:

h*p://www.domain.com/foo/bar.x
h
*p://www.domain.com/foo/bar.x.y
h**p://www.domain.com/foo/bar.x.y.z

XJC produces packages as follows:

com.domain.foo.bar.x and places generated java files from "...x" and "...x.y" xsd namespaces there

com.domain.foo.bar.x_y and places generated java files from "...x.y.z" xsd namespaces there

What I would like to achieve here is proper:

com.domain.foo.bar.x
com.domain.foo.bar.x.y
com.domain.foo.bar.x.y.z package names

Is this somehow possible? Maybe using custom JAXB bindings? I've studied jaxb custom binding docs but I am not sure if it's possible.

Basically I would like xjc to treat both "/" and "." as package separators.

Any help appreciated.

Adalbert

A: 

Use jaxb:package customization:

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

    <jaxb:bindings schemaLocation="schema.xsd" node="/xsd:schema">
        <jaxb:schemaBindings>
            <jaxb:package name="com.domain.foo.bar.x.y.z"/>
        </jaxb:schemaBindings>
    </jaxb:bindings>
</jaxb:bindings>

Alternatively you could rename you namespace into h**p://www.domain.com/foo/bar/x/y/z.

lexicore