I'm trying to use annotations at package level but I get compilation erros from Eclipse.
I have a class Head
with the following package/annotation:
@javax.xml.bind.annotation.XmlSchema (
xmlns = {
@javax.xml.bind.annotation.XmlNs(prefix = "com",
namespaceURI="http://es.indra.transporte.common"),
@javax.xml.bind.annotation.XmlNs( namespaceURI="http://www.w3.org/2001/XMLSchema")
},
namespace = "http://es.indra.transporte.common",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
attributeFormDefault = javax.xml.bind.ann开发者_开发技巧otation.XmlNsForm.UNQUALIFIED
)
package es.indra.transporte.central.thalesinterface.common.beans;
I have created a package-info.java
in es.indra.transporte.central.thalesinterface.common.beans
folder with the above code but I'm still getting the compilation error
Package annotations must be in file
package-info.java
in Head
class. I'm using jdk6.
The only problem I got when trying to compile your package info was that the @XmlNs annotation was missing the prefix property.
This:
@javax.xml.bind.annotation.XmlNs( namespaceURI="http://www.w3.org/2001/XMLSchema")
Should be:
@javax.xml.bind.annotation.XmlNs(prefix="xsd", namespaceURI="http://www.w3.org/2001/XMLSchema")
The following corrected code should compile:
@javax.xml.bind.annotation.XmlSchema (
xmlns = {
@javax.xml.bind.annotation.XmlNs(prefix = "com",
namespaceURI="http://es.indra.transporte.common"),
@javax.xml.bind.annotation.XmlNs(prefix="xsd", namespaceURI="http://www.w3.org/2001/XMLSchema")
},
namespace = "http://es.indra.transporte.common",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED
)
package es.indra.transporte.central.thalesinterface.common.beans;
For an example see:
- http://bdoughan.blogspot.com/2010/08/jaxb-namespaces.html
精彩评论