为JAXB生成的package-info添加注释 [英] Adding annotations to package-info generated by JAXB
问题描述
我一直在使用 annox 在我的jaxb生成的类上添加注释(通过绑定文件)但我找不到直接在包上添加注释的方法(package-info.java)。
我一直在努力做我的bindings.xml中有类似的东西:
< jaxb:schemaBindings>
< jaxb:package name =my.package>
< annox:annotate>
< annox:annotate annox:class =my.Annotation/>
< / annox:annotate>
< / jaxb:package>
< / jaxb:schemaBindings>
但jaxb抱怨 annox:annotate
是预计不会在那里。
还有其他办法吗?
作者在这里。
目前不支持此功能,但可以轻松实现。
请在此处提出问题: https://github.com/highsource/annox/issues
这样做的方法是使用 @ target =package
。因此,您必须自定义此包中的内容(类,无论如何)并将目标
属性设置为包
。然后注释将转到 package-info.java
。
UPDATE <这是在JAXB2 Annotate Plugin 1.0.0中实现的。
https://github.com/highsource/jaxb2-annotate-plugin/issues/1
示例:
< 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.xsdnode =/ 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>
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?
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
<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>
这篇关于为JAXB生成的package-info添加注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!