Adding annotations to package-info generated by JAXB

余生长醉 提交于 2019-12-11 12:34:28

问题


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:


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>


来源:https://stackoverflow.com/questions/25184035/adding-annotations-to-package-info-generated-by-jaxb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!