Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5930457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:33:28+00:00 2026-05-22T14:33:28+00:00

I am using the maven plugin maven-jaxb2-plugin to generate POJOs from a XSD Schema

  • 0

I am using the maven plugin maven-jaxb2-plugin to generate POJOs from a XSD Schema file.
This works fine. The only thing, thats really bothering me is, that the xml schema enumerations are not mapped in a Java Enum Type.

My maven plugin is generating the java pojos from a file I called schemachooser.xsd

schemachooser.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:sch="http://www.ascc.net/xml/schematron" 
targetNamespace="http://schema.something" elementFormDefault="qualified"
version="1.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc" jaxb:version="1.0">

<xs:annotation>
    <xs:appinfo>
        <jaxb:globalBindings generateIsSetMethod="true" fixedAttributeAsConstantProperty="true">
            <xjc:serializable />
        </jaxb:globalBindings>
        <jaxb:schemaBindings>
           <jaxb:bindings node="//xsd:element[@name='ElementName']/xsd:simpleType">
               <jaxb:typesafeEnumClass name="MyEnumType" />
           </jaxb:bindings>
        </jaxb:schemaBindings>
    </xs:appinfo>
</xs:annotation>

<xs:include schemaLocation="myNormalSchema.xsd" />

</schema>

It does generate the files, but not the “new” Enum Class “MyEnumType”. Am I using the bindings wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:33:29+00:00Added an answer on May 22, 2026 at 2:33 pm

    If you want to keep the JAXB annotations separate from the XML schema then you need to use an JAXB bindings file:

    bindings.xml

    <jaxb:bindings 
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
        xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
        jaxb:extensionBindingPrefixes="xjc"
        version="2.1">
        <jaxb:globalBindings generateIsSetMethod="true" fixedAttributeAsConstantProperty="true">
            <xjc:serializable />
        </jaxb:globalBindings>
        <jaxb:bindings schemaLocation="myNormalSchema.xsd">
            <jaxb:bindings node="//xs:element[@name='ElementName']/xs:simpleType">
                   <jaxb:typesafeEnumClass name="MyEnumType" />
            </jaxb:bindings>
       </jaxb:bindings>
    </jaxb:bindings>
    

    myNormalSchema.xsd

    Below is a sample XML schema that a reverse engineered from your question:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema 
        targetNamespace="http://www.example.com" 
         xmlns="http://www.example.com" 
         xmlns:xs="http://www.w3.org/2001/XMLSchema">
    
        <xs:element name="ElementName">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="MY_ENUM_1"/>
                    <xs:enumeration value="MY_ENUM_2"/>
                </xs:restriction>
            </xs:simpleType>
       </xs:element>
    
        <xs:element name="Root">
            <xs:complexType>
                <xs:sequence>
                    <xs:element ref="ElementName"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    
    </xs:schema>
    

    XJC Call

    xjc -extension -d out -b bindings.xml myNormalSchema.xsd
    

    MyEnumType

    One of the generated classes is an enum called MyEnumType.

    package com.example;
    
    import javax.xml.bind.annotation.XmlEnum;
    import javax.xml.bind.annotation.XmlType;
    
    @XmlType(name = "")
    @XmlEnum
    public enum MyEnumType {
    
        MY_ENUM_1,
        MY_ENUM_2;
    
        public String value() {
            return name();
        }
    
        public static MyEnumType fromValue(String v) {
            return valueOf(v);
        }
    
    }
    

    Root

    Also the Root class is generated with the isSet method:

    package com.example;
    
    import java.io.Serializable;
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlType;
    
    
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "elementName"
    })
    @XmlRootElement(name = "Root")
    public class Root
        implements Serializable
    {
    
        @XmlElement(name = "ElementName", required = true)
        protected MyEnumType elementName;
    
        public MyEnumType getElementName() {
            return elementName;
        }
    
        public void setElementName(MyEnumType value) {
            this.elementName = value;
        }
    
        public boolean isSetElementName() {
            return (this.elementName!= null);
        }
    
    }
    

    Examples

    • http://bdoughan.blogspot.com/2011/05/schema-to-java-xmlmimetype.html
    • http://bdoughan.blogspot.com/2011/04/xml-schema-to-java-xsd-choice.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im using maven-jaxb2-plugin to generate from a 1.0xsd file: <plugin> <groupId>org.jvnet.jaxb2.maven2</groupId> <artifactId>maven-jaxb2-plugin</artifactId> <executions> <execution>
I'm trying to generate beans from an xsd by using the jaxb2-maven-plugin maven plugin,
The code I'm working on is using jaxb2-maven-plugin from org.codehaus.mojo to generate Java classes
I'd like to generate Java source code from an XML Schema file using JAXB2
I am using maven-buildnumber-plugin version 1.0-beta-4. This works fine on a project checked out
I'm using the maven jaxb2 plugin to generate Java classes, built from schemas in
What's the easiest/best way to generate Java from an XSD using MOXy under Maven-3?
I'm trying to automatically compress both CSS and JS using maven and this plugin
I'm generating Java classes from a WSDL using the jaxws-maven-plugin's wsimport goal. Out of
I have followed this thread now when i try to build using maven plugin

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.