Adding annotations to package-info generated by JAXB

3.7k views Asked by At

I have been using annox to add annotations on my jaxb-generated classes (through bindings files) but I can't find a way to add annotations directly on the package (package-info.java).

I've been trying to do something like this in my bindings.xml:

<jaxb:schemaBindings>
    <jaxb:package name="my.package">
        <annox:annotate>
            <annox:annotate annox:class="my.Annotation" />
        </annox:annotate>
    </jaxb:package>
</jaxb:schemaBindings>

but jaxb complains that annox:annotate is not expected to be there.

Is there another way to do it?

1

There are 1 answers

0
lexicore On BEST ANSWER

Author here.

This is not supported a the moment, but can be easily implemented. Please file an issue here: https://github.com/highsource/annox/issues

The way this will be done is using @target="package". So you'll have to customize something in this package (a class, whatever) and set the target attribute to package. The annotation will then go to the package-info.java.

UPDATE

This is implemented in JAXB2 Annotate Plugin 1.0.0.

https://github.com/highsource/jaxb2-annotate-plugin/issues/1

Example:

<jaxb:bindings
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:annox="http://annox.dev.java.net"
    jaxb:extensionBindingPrefixes="annox"

    jaxb:version="2.1">

    <jaxb:bindings schemaLocation="schema.xsd" node="/xsd:schema">
        <jaxb:bindings node="xsd:complexType[@name='issueJIIB43Type']">
            <annox:annotate target="class">@javax.xml.bind.annotation.XmlRootElement("someElement")</annox:annotate>
            <annox:annotate target="package">@javax.xml.bind.annotation.XmlSchema(elementFormDefault=javax.xml.bind.annotation.XmlNsForm.QUALIFIED)</annox:annotate>
            <annox:annotatePackage>@javax.annotation.Generated({"XJC"})</annox:annotatePackage>
        </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>