@xmlschema jaxb package-info.java compilation error

跟風遠走 提交于 2020-01-03 16:57:16

问题


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.annotation.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.


回答1:


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


来源:https://stackoverflow.com/questions/4828131/xmlschema-jaxb-package-info-java-compilation-error

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