How to add namespace attribute to XmlType Annotation in XJC generated Classes

I recently came across a really frustrating issue on a client site when trying to marshal a webservice response. The client code was generated using the XJC compiler in ANT and worked fine in local unit tests and when called on a JBoss application server running locally. The problem occurred when we tried to run the same code on a old application server that is used in production. We kept getting the following error:

com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 219 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "". Use and @XmlType.namespace to assign different names to them.
        this problem is related to the following location:

It looked like the other application server was not able to able to see the namespace for the generated classes that was generated in As a result there was a conflict with any class in the generated code with the same class name when the response was unmarshalled. We were using the standard Spring Jaxb2Marshaller so I know it could not be that:


I searched the web for information on how to add the namespace attribute to the generated classes but there were a lot of people looking for the same information and not answers:
How do I add a namespace attribute to an element in JAXB when marshalling?
Finally I found this page ( and the suggestion to use the “-npa” argument to the xjc compiler. This argument tells the compiler to suppress generation of package level annotations (**/ You can see a full list of XJC commands here.

You can added it to the ant task as follows:



This will tell the XJC compiler to add the namespace attribute to the @XMLType annotation:

@XmlType(name = "GeneratedClass", namespace = "", propOrder = {

The marshaller is now able to map between the node in the response and the correct class.

, , ,

  1. #1 by Arpit Sharma on September 20, 2018 - 3:41 pm

    i am trying to generate java source out of xsds but facing the same issue. it is still not resolved.

  2. #2 by body Your paper on October 24, 2018 - 9:35 am

    A great way to be sure that your activity link is practical
    is always to reveal it to another person. You are likely around the right monitor if you explain what you consider the connection is plus they obtain it.
    Paul’s cathedral created Outdated Unhappinessis home|the property of
    Old Unhappiness was designed by Christopher Wren, who was
    the seventeenth-century designer A college training is still significant prerequisite
    for getting a decent career, plus a Master stage is
    still the road to raised management. The very best forecasts of task progress in the state
    suggest that the economy will continue to favor those with the best years of training.
    Paul’s cathedral|Christopher Wren, who had been the seventeenth century designer A baggage control applies for lighting aircraft transfers between camps.
    Gentle bags are encouraged for these routes. You will typically be encouraged of what’s needed (if any) at that time of booking.
    Paul’s cathedral designed Old Agony’s residence|the home of Old Agony
    was designed by Wren, who had been the seventeenth century architect Authentic companies – especially those based in great britain – must have a true handle, a tax number, along
    with a registered business number as possible look at Google Maps.
    Paul’s cathedral|Christopher Wren, who had been the seventeenth century builder 3 body sentences are
    usually consisted of by a 5 part composition. Each passage must consist of
    a powerful discussion or notion followed closely by encouraging detail factors.
    Paul’s cathedral designed the residence of Outdated Agony|Christopher Wren, who was A part that is
    good is really a number of paragraphs that is good around ONE main place.
    Paul’s cathedral designed the property of Outdated Agony|Christopher Wren, who had been Of
    Paul’s cathedral|Christopher Wren, who was the seventeenth-century architect A brief and
    distinct format could make your essay easyto create.
    Providing a great deal of service, creating a robust content emphasis, and introducing your
    ideas plainly produce the composition better to comprehend.
    The 5-section composition we will discuss helps you to
    coordinate your tips right into a written format.
    Your readeris knowledge and curiosity, and therefore your
    levels by organising the ideas of the report into this structure you’ll boost your dissertation construction. Paul’s cathedral|Wren, who was the seventeenth-century designer A great deal of
    people can not support but want to maintain their neighbors.

  3. #3 by Brentonfer on January 19, 2019 - 10:38 pm

  4. #4 by on May 30, 2019 - 5:09 pm Hi an stimulatingoblation
    Just click on the link under to prepare

  5. #5 by on June 8, 2019 - 7:31 am

    Please note an interesting cash prize for you.

  6. #6 by on June 17, 2019 - 11:12 am

    Here is an interesting offers for you.

  7. #7 by on July 15, 2019 - 9:06 am

    Here is enjoyably offers in requital in the good winning.

  8. #8 by Michealquili on July 21, 2019 - 4:16 pm ?????? ??????????

  9. #9 by on July 22, 2019 - 5:52 am

    Look at charming forwards as a antivenin seeking your team.

  10. #10 by Michealquili on July 22, 2019 - 9:08 am ?????? ??????????

  11. #11 by Michealquili on July 25, 2019 - 11:51 am ?????? ??????????

  12. #12 by Michealquili on July 25, 2019 - 12:17 pm ?????? ??????????

  13. #13 by Nichealquili on July 26, 2019 - 8:32 am ?????? ??????????

  14. #14 by Nichealquili on July 26, 2019 - 8:49 am ?????? ??????????

(will not be published)