{"id":34289,"date":"2016-03-02T11:00:05","date_gmt":"2016-03-02T09:00:05","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=34289"},"modified":"2016-03-01T10:35:53","modified_gmt":"2016-03-01T08:35:53","slug":"jaxb-generate-classes-xsd","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/","title":{"rendered":"JAXB: Generate Classes from XSD"},"content":{"rendered":"<p>In this tutorial, we shall learn generating classes from XML Schema Design (XSD) using JAXB. This can be achieved using JAXB binding compiler <code>XJC<\/code> command. <code>XJC<\/code> is included in the <i>bin<\/i> directory in the <i>JDK<\/i> starting with Java SE 6.<\/p>\n<h2>1. Requirements<\/h2>\n<p>To see this example in action, following is the minimum requirement:<\/p>\n<ol>\n<li>JDK 6 (Java SE 6) or later<\/li>\n<li>JAXB 2.1 API<\/li>\n<\/ol>\n<h2>2. XJC command<\/h2>\n<p>The JAXB <code>XJC<\/code> schema binding compiler transforms\/binds, a source XML schema (XSD) to a set of JAXB content classes in the Java programming language. <\/p>\n<p>To see the usage of <code>XJC<\/code> command, just type in the same in command prompt\/shell:<\/p>\n<p><figure id=\"attachment_34294\" aria-describedby=\"caption-attachment-34294\" style=\"width: 801px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/XJCCommandUsage.jpg\" rel=\"attachment wp-att-34294\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/XJCCommandUsage.jpg\" alt=\"XJC Command Usage\" width=\"801\" height=\"686\" class=\"size-full wp-image-34294\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/XJCCommandUsage.jpg 801w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/XJCCommandUsage-300x257.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/XJCCommandUsage-768x658.jpg 768w\" sizes=\"(max-width: 801px) 100vw, 801px\" \/><\/a><figcaption id=\"caption-attachment-34294\" class=\"wp-caption-text\">XJC Command Usage<\/figcaption><\/figure><\/p>\n<h2>3. XJC in Action: Generating classes form XSD<\/h2>\n<p>To see the command <code>XJC<\/code> in action, we will need an XSD file. We will be using following XSD file in our example.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Employee.xsd<\/em><\/span><\/p>\n<pre class=\"brush:xml\">\r\n&lt;xs:schema attributeFormDefault=&quot;unqualified&quot; elementFormDefault=&quot;qualified&quot; xmlns:xs=&quot;http:\/\/www.w3.org\/2001\/XMLSchema&quot;&gt;\r\n  &lt;xs:element name=&quot;employee&quot;&gt;\r\n    &lt;xs:complexType&gt;\r\n      &lt;xs:sequence&gt;\r\n        &lt;xs:element type=&quot;xs:byte&quot; name=&quot;id&quot;\/&gt;\r\n        &lt;xs:element type=&quot;xs:string&quot; name=&quot;name&quot;\/&gt;\r\n        &lt;xs:element name=&quot;address&quot;&gt;\r\n          &lt;xs:complexType&gt;\r\n            &lt;xs:sequence&gt;\r\n              &lt;xs:element type=&quot;xs:string&quot; name=&quot;addressLine1&quot;\/&gt;\r\n              &lt;xs:element type=&quot;xs:string&quot; name=&quot;addressLine2&quot;\/&gt;\r\n              &lt;xs:element type=&quot;xs:string&quot; name=&quot;country&quot;\/&gt;\r\n              &lt;xs:element type=&quot;xs:string&quot; name=&quot;state&quot;\/&gt;\r\n              &lt;xs:element type=&quot;xs:short&quot; name=&quot;zip&quot;\/&gt;\r\n            &lt;\/xs:sequence&gt;\r\n          &lt;\/xs:complexType&gt;\r\n        &lt;\/xs:element&gt;\r\n        &lt;xs:element type=&quot;xs:string&quot; name=&quot;assestsAllocated&quot; maxOccurs=&quot;unbounded&quot; minOccurs=&quot;0&quot;\/&gt;\r\n      &lt;\/xs:sequence&gt;\r\n    &lt;\/xs:complexType&gt;\r\n  &lt;\/xs:element&gt;\r\n&lt;\/xs:schema&gt;\r\n<\/pre>\n<p>To run the command, we shall browse to the directory having the xsd file, and then we shall execute following command:<br \/>\n<code>xjc -d src -p com.javacodegeeks.examples.xjc Employee.xsd<\/code><\/p>\n<p>Here <code>-d<\/code> specifies to which folder generated classes shall go. In this case it shall be <i>src<\/i> directory, make sure that the target directory exists. <code>-p<\/code> specifies the target package structure. In this case it would be <i>com.javacodegeeks.examples.xjc<\/i><\/p>\n<p>Following shall be the output of above command:<\/p>\n<p><figure id=\"attachment_34298\" aria-describedby=\"caption-attachment-34298\" style=\"width: 704px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/XJC-Execution.jpg\" rel=\"attachment wp-att-34298\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/XJC-Execution.jpg\" alt=\"XJC Execution\" width=\"704\" height=\"88\" class=\"size-full wp-image-34298\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/XJC-Execution.jpg 704w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/XJC-Execution-300x38.jpg 300w\" sizes=\"(max-width: 704px) 100vw, 704px\" \/><\/a><figcaption id=\"caption-attachment-34298\" class=\"wp-caption-text\">XJC Execution<\/figcaption><\/figure><\/p>\n<p>And we can see the package structure is created in the desired manner:<\/p>\n<p><figure id=\"attachment_34302\" aria-describedby=\"caption-attachment-34302\" style=\"width: 539px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/Package-Structure-1.jpg\" rel=\"attachment wp-att-34302\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/Package-Structure-1.jpg\" alt=\"Package Structure\" width=\"539\" height=\"195\" class=\"size-full wp-image-34302\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/Package-Structure-1.jpg 539w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/Package-Structure-1-300x109.jpg 300w\" sizes=\"(max-width: 539px) 100vw, 539px\" \/><\/a><figcaption id=\"caption-attachment-34302\" class=\"wp-caption-text\">Package Structure<\/figcaption><\/figure><\/p>\n<p>Now let us see the java files created.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Employee.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">\r\n\/\/\r\n\/\/ This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r\n\/\/ See <a href=\"http:\/\/java.sun.com\/xml\/jaxb\">http:\/\/java.sun.com\/xml\/jaxb<\/a> \r\n\/\/ Any modifications to this file will be lost upon recompilation of the source schema. \r\n\/\/ Generated on: 2016.02.28 at 03:27:10 PM IST \r\n\/\/\r\n\r\n\r\npackage com;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\nimport javax.xml.bind.annotation.XmlAccessType;\r\nimport javax.xml.bind.annotation.XmlAccessorType;\r\nimport javax.xml.bind.annotation.XmlElement;\r\nimport javax.xml.bind.annotation.XmlRootElement;\r\nimport javax.xml.bind.annotation.XmlType;\r\n\r\n\r\n\/**\r\n * &lt;p&gt;Java class for anonymous complex type.\r\n * \r\n * &lt;p&gt;The following schema fragment specifies the expected content contained within this class.\r\n * \r\n * &lt;complexType&gt;\r\n *   &lt;complexContent&gt;\r\n *     &lt;restriction base=\"{http:\/\/www.w3.org\/2001\/XMLSchema}anyType\"&gt;\r\n *       &lt;sequence&gt;\r\n *         &lt;element name=\"name\" type=\"{http:\/\/www.w3.org\/2001\/XMLSchema}string\"\/&gt;\r\n *         &lt;element name=\"address\"&gt;\r\n *           &lt;complexType&gt;\r\n *             &lt;complexContent&gt;\r\n *               &lt;restriction base=\"{http:\/\/www.w3.org\/2001\/XMLSchema}anyType\"&gt;\r\n *                 &lt;sequence&gt;\r\n *                   &lt;element name=\"addressLine1\" type=\"{http:\/\/www.w3.org\/2001\/XMLSchema}string\"\/&gt;\r\n *                   &lt;element name=\"addressLine2\" type=\"{http:\/\/www.w3.org\/2001\/XMLSchema}string\"\/&gt;\r\n *                   &lt;element name=\"country\" type=\"{http:\/\/www.w3.org\/2001\/XMLSchema}string\"\/&gt;\r\n *                   &lt;element name=\"state\" type=\"{http:\/\/www.w3.org\/2001\/XMLSchema}string\"\/&gt;\r\n *                   &lt;element name=\"zip\" type=\"{http:\/\/www.w3.org\/2001\/XMLSchema}short\"\/&gt;\r\n *                 &lt;\/sequence&gt;\r\n *               &lt;\/restriction&gt;\r\n *             &lt;\/complexContent&gt;\r\n *           &lt;\/complexType&gt;\r\n *         &lt;\/element&gt;\r\n *         &lt;element name=\"assestsAllocated\" type=\"{http:\/\/www.w3.org\/2001\/XMLSchema}string\" maxOccurs=\"unbounded\" minOccurs=\"0\"\/&gt;\r\n *         &lt;element name=\"id\" type=\"{http:\/\/www.w3.org\/2001\/XMLSchema}byte\"\/&gt;\r\n *       &lt;\/sequence&gt;\r\n *     &lt;\/restriction&gt;\r\n *   &lt;\/complexContent&gt;\r\n * &lt;\/complexType&gt;\r\n * \r\n * \r\n *\/\r\n@XmlAccessorType(XmlAccessType.FIELD)\r\n@XmlType(name = \"\", propOrder = {\r\n    \"name\",\r\n    \"address\",\r\n    \"assestsAllocated\",\r\n    \"id\"\r\n})\r\n@XmlRootElement(name = \"employee\")\r\npublic class Employee {\r\n\r\n    @XmlElement(required = true)\r\n    protected String name;\r\n    @XmlElement(required = true)\r\n    protected Employee.Address address;\r\n    protected List assestsAllocated;\r\n    protected byte id;\r\n\r\n    \/**\r\n     * Gets the value of the name property.\r\n     * \r\n     * @return\r\n     *     possible object is\r\n     *     {@link String }\r\n     *     \r\n     *\/\r\n    public String getName() {\r\n        return name;\r\n    }\r\n\r\n    \/**\r\n     * Sets the value of the name property.\r\n     * \r\n     * @param value\r\n     *     allowed object is\r\n     *     {@link String }\r\n     *     \r\n     *\/\r\n    public void setName(String value) {\r\n        this.name = value;\r\n    }\r\n\r\n    \/**\r\n     * Gets the value of the address property.\r\n     * \r\n     * @return\r\n     *     possible object is\r\n     *     {@link Employee.Address }\r\n     *     \r\n     *\/\r\n    public Employee.Address getAddress() {\r\n        return address;\r\n    }\r\n\r\n    \/**\r\n     * Sets the value of the address property.\r\n     * \r\n     * @param value\r\n     *     allowed object is\r\n     *     {@link Employee.Address }\r\n     *     \r\n     *\/\r\n    public void setAddress(Employee.Address value) {\r\n        this.address = value;\r\n    }\r\n\r\n    \/**\r\n     * Gets the value of the assestsAllocated property.\r\n     * \r\n     * &lt;p&gt;\r\n     * This accessor method returns a reference to the live list,\r\n     * not a snapshot. Therefore any modification you make to the\r\n     * returned list will be present inside the JAXB object.\r\n     * This is why there is not a <CODE>set<\/CODE> method for the assestsAllocated property.\r\n     * \r\n     * &lt;p&gt;\r\n     * For example, to add a new item, do as follows:\r\n     *    getAssestsAllocated().add(newItem);\r\n     * \r\n     * \r\n     * &lt;p&gt;\r\n     * Objects of the following type(s) are allowed in the list\r\n     * {@link String }\r\n     * \r\n     * \r\n     *\/\r\n    public List getAssestsAllocated() {\r\n        if (assestsAllocated == null) {\r\n            assestsAllocated = new ArrayList();\r\n        }\r\n        return this.assestsAllocated;\r\n    }\r\n\r\n    \/**\r\n     * Gets the value of the id property.\r\n     * \r\n     *\/\r\n    public byte getId() {\r\n        return id;\r\n    }\r\n\r\n    \/**\r\n     * Sets the value of the id property.\r\n     * \r\n     *\/\r\n    public void setId(byte value) {\r\n        this.id = value;\r\n    }\r\n\r\n\r\n    \/**\r\n     * &lt;p&gt;Java class for anonymous complex type.\r\n     * \r\n     * &lt;p&gt;The following schema fragment specifies the expected content contained within this class.\r\n     * \r\n     * &lt;complexType&gt;\r\n     *   &lt;complexContent&gt;\r\n     *     &lt;restriction base=\"{http:\/\/www.w3.org\/2001\/XMLSchema}anyType\"&gt;\r\n     *       &lt;sequence&gt;\r\n     *         &lt;element name=\"addressLine1\" type=\"{http:\/\/www.w3.org\/2001\/XMLSchema}string\"\/&gt;\r\n     *         &lt;element name=\"addressLine2\" type=\"{http:\/\/www.w3.org\/2001\/XMLSchema}string\"\/&gt;\r\n     *         &lt;element name=\"country\" type=\"{http:\/\/www.w3.org\/2001\/XMLSchema}string\"\/&gt;\r\n     *         &lt;element name=\"state\" type=\"{http:\/\/www.w3.org\/2001\/XMLSchema}string\"\/&gt;\r\n     *         &lt;element name=\"zip\" type=\"{http:\/\/www.w3.org\/2001\/XMLSchema}short\"\/&gt;\r\n     *       &lt;\/sequence&gt;\r\n     *     &lt;\/restriction&gt;\r\n     *   &lt;\/complexContent&gt;\r\n     * &lt;\/complexType&gt;\r\n     * \r\n     * \r\n     *\/\r\n    @XmlAccessorType(XmlAccessType.FIELD)\r\n    @XmlType(name = \"\", propOrder = {\r\n        \"addressLine1\",\r\n        \"addressLine2\",\r\n        \"country\",\r\n        \"state\",\r\n        \"zip\"\r\n    })\r\n    public static class Address {\r\n\r\n        @XmlElement(required = true)\r\n        protected String addressLine1;\r\n        @XmlElement(required = true)\r\n        protected String addressLine2;\r\n        @XmlElement(required = true)\r\n        protected String country;\r\n        @XmlElement(required = true)\r\n        protected String state;\r\n        protected short zip;\r\n\r\n        \/**\r\n         * Gets the value of the addressLine1 property.\r\n         * \r\n         * @return\r\n         *     possible object is\r\n         *     {@link String }\r\n         *     \r\n         *\/\r\n        public String getAddressLine1() {\r\n            return addressLine1;\r\n        }\r\n\r\n        \/**\r\n         * Sets the value of the addressLine1 property.\r\n         * \r\n         * @param value\r\n         *     allowed object is\r\n         *     {@link String }\r\n         *     \r\n         *\/\r\n        public void setAddressLine1(String value) {\r\n            this.addressLine1 = value;\r\n        }\r\n\r\n        \/**\r\n         * Gets the value of the addressLine2 property.\r\n         * \r\n         * @return\r\n         *     possible object is\r\n         *     {@link String }\r\n         *     \r\n         *\/\r\n        public String getAddressLine2() {\r\n            return addressLine2;\r\n        }\r\n\r\n        \/**\r\n         * Sets the value of the addressLine2 property.\r\n         * \r\n         * @param value\r\n         *     allowed object is\r\n         *     {@link String }\r\n         *     \r\n         *\/\r\n        public void setAddressLine2(String value) {\r\n            this.addressLine2 = value;\r\n        }\r\n\r\n        \/**\r\n         * Gets the value of the country property.\r\n         * \r\n         * @return\r\n         *     possible object is\r\n         *     {@link String }\r\n         *     \r\n         *\/\r\n        public String getCountry() {\r\n            return country;\r\n        }\r\n\r\n        \/**\r\n         * Sets the value of the country property.\r\n         * \r\n         * @param value\r\n         *     allowed object is\r\n         *     {@link String }\r\n         *     \r\n         *\/\r\n        public void setCountry(String value) {\r\n            this.country = value;\r\n        }\r\n\r\n        \/**\r\n         * Gets the value of the state property.\r\n         * \r\n         * @return\r\n         *     possible object is\r\n         *     {@link String }\r\n         *     \r\n         *\/\r\n        public String getState() {\r\n            return state;\r\n        }\r\n\r\n        \/**\r\n         * Sets the value of the state property.\r\n         * \r\n         * @param value\r\n         *     allowed object is\r\n         *     {@link String }\r\n         *     \r\n         *\/\r\n        public void setState(String value) {\r\n            this.state = value;\r\n        }\r\n\r\n        \/**\r\n         * Gets the value of the zip property.\r\n         * \r\n         *\/\r\n        public short getZip() {\r\n            return zip;\r\n        }\r\n\r\n        \/**\r\n         * Sets the value of the zip property.\r\n         * \r\n         *\/\r\n        public void setZip(short value) {\r\n            this.zip = value;\r\n        }\r\n\r\n    }\r\n\r\n}\r\n<\/pre>\n<p>We can see that <i>Employee.java<\/i> also has static class <code>Address<\/code> as it was desired.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Also we can see that an unexpected <i>ObjectFactory.java<\/i> is also created. This contains factory methods to create objects of classes created. This can come into use when creating JAXBElement representation of objects.<\/p>\n<p><span style=\"text-decoration: underline\"><em>ObjectFactory.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">\/\/\r\n\/\/ This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r\n\/\/ See &lt;a href=\"http:\/\/java.sun.com\/xml\/jaxb\"&gt;http:\/\/java.sun.com\/xml\/jaxb&lt;\/a&gt; \r\n\/\/ Any modifications to this file will be lost upon recompilation of the source schema. \r\n\/\/ Generated on: 2016.02.27 at 09:09:47 PM IST \r\n\/\/\r\n\r\n\r\npackage com.javacodegeeks.examples.xjc;\r\n\r\nimport javax.xml.bind.annotation.XmlRegistry;\r\n\r\n\r\n\/**\r\n * This object contains factory methods for each \r\n * Java content interface and Java element interface \r\n * generated in the com.javacodegeeks.examples.xjc package. \r\n * &lt;p&gt;An ObjectFactory allows you to programatically \r\n * construct new instances of the Java representation \r\n * for XML content. The Java representation of XML \r\n * content can consist of schema derived interfaces \r\n * and classes representing the binding of schema \r\n * type definitions, element declarations and model \r\n * groups.  Factory methods for each of these are \r\n * provided in this class.\r\n * \r\n *\/\r\n@XmlRegistry\r\npublic class ObjectFactory {\r\n\r\n\r\n    \/**\r\n     * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.javacodegeeks.examples.xjc\r\n     * \r\n     *\/\r\n    public ObjectFactory() {\r\n    }\r\n\r\n    \/**\r\n     * Create an instance of {@link Employee }\r\n     * \r\n     *\/\r\n    public Employee createEmployee() {\r\n        return new Employee();\r\n    }\r\n\r\n    \/**\r\n     * Create an instance of {@link Employee.Address }\r\n     * \r\n     *\/\r\n    public Employee.Address createEmployeeAddress() {\r\n        return new Employee.Address();\r\n    }\r\n\r\n}<\/pre>\n<h2>4. Conclusion<\/h2>\n<p>In this example, we learnt what is <code>XJC<\/code>, how to generate binding Java classes from an XSD, and the sample code generated. The code generated was the desired class type and the object factory that can be used to create objects of the generated class.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we shall learn generating classes from XML Schema Design (XSD) using JAXB. This can be achieved using JAXB binding compiler XJC command. XJC is included in the bin directory in the JDK starting with Java SE 6. 1. Requirements To see this example in action, following is the minimum requirement: JDK 6 &hellip;<\/p>\n","protected":false},"author":75,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[391],"tags":[1392,1347,1393,1391],"class_list":["post-34289","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bind","tag-generate-classes","tag-jax-b","tag-xjc","tag-xsd"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JAXB: Generate Classes from XSD - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this tutorial, we shall learn generating classes from XML Schema Design (XSD) using JAXB. This can be achieved using JAXB binding compiler XJC command.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JAXB: Generate Classes from XSD - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, we shall learn generating classes from XML Schema Design (XSD) using JAXB. This can be achieved using JAXB binding compiler XJC command.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-03-02T09:00:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Saurabh Arora\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Saurabh Arora\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/\"},\"author\":{\"name\":\"Saurabh Arora\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/5bf4e0274824642c44536b83ddbfaf6c\"},\"headline\":\"JAXB: Generate Classes from XSD\",\"datePublished\":\"2016-03-02T09:00:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/\"},\"wordCount\":346,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"keywords\":[\"generate classes\",\"jax-b\",\"XJC\",\"xsd\"],\"articleSection\":[\"bind\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/\",\"name\":\"JAXB: Generate Classes from XSD - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2016-03-02T09:00:05+00:00\",\"description\":\"In this tutorial, we shall learn generating classes from XML Schema Design (XSD) using JAXB. This can be achieved using JAXB binding compiler XJC command.\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"xml\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/xml\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"bind\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/xml\/bind\/\"},{\"@type\":\"ListItem\",\"position\":6,\"name\":\"JAXB: Generate Classes from XSD\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/5bf4e0274824642c44536b83ddbfaf6c\",\"name\":\"Saurabh Arora\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/Saurabh-Arora-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/Saurabh-Arora-96x96.jpg\",\"caption\":\"Saurabh Arora\"},\"description\":\"Saurabh graduated with an engineering degree in Information Technology from YMCA Institute of Engineering, India. He is SCJP, OCWCD certified and currently working as Technical Lead with one of the biggest service based firms and is involved in projects extensively using Java and JEE technologies. He has worked in E-Commerce, Banking and Telecom domain.\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\/\",\"https:\/\/in.linkedin.com\/in\/saurabh-arora-78674b18\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/saurabh-arora\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JAXB: Generate Classes from XSD - Java Code Geeks","description":"In this tutorial, we shall learn generating classes from XML Schema Design (XSD) using JAXB. This can be achieved using JAXB binding compiler XJC command.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/","og_locale":"en_US","og_type":"article","og_title":"JAXB: Generate Classes from XSD - Java Code Geeks","og_description":"In this tutorial, we shall learn generating classes from XML Schema Design (XSD) using JAXB. This can be achieved using JAXB binding compiler XJC command.","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2016-03-02T09:00:05+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Saurabh Arora","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Saurabh Arora","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/"},"author":{"name":"Saurabh Arora","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/5bf4e0274824642c44536b83ddbfaf6c"},"headline":"JAXB: Generate Classes from XSD","datePublished":"2016-03-02T09:00:05+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/"},"wordCount":346,"commentCount":2,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","keywords":["generate classes","jax-b","XJC","xsd"],"articleSection":["bind"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/","name":"JAXB: Generate Classes from XSD - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2016-03-02T09:00:05+00:00","description":"In this tutorial, we shall learn generating classes from XML Schema Design (XSD) using JAXB. This can be achieved using JAXB binding compiler XJC command.","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-generate-classes-xsd\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"xml","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/xml\/"},{"@type":"ListItem","position":5,"name":"bind","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/xml\/bind\/"},{"@type":"ListItem","position":6,"name":"JAXB: Generate Classes from XSD"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/5bf4e0274824642c44536b83ddbfaf6c","name":"Saurabh Arora","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/Saurabh-Arora-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/Saurabh-Arora-96x96.jpg","caption":"Saurabh Arora"},"description":"Saurabh graduated with an engineering degree in Information Technology from YMCA Institute of Engineering, India. He is SCJP, OCWCD certified and currently working as Technical Lead with one of the biggest service based firms and is involved in projects extensively using Java and JEE technologies. He has worked in E-Commerce, Banking and Telecom domain.","sameAs":["http:\/\/www.javacodegeeks.com\/","https:\/\/in.linkedin.com\/in\/saurabh-arora-78674b18"],"url":"https:\/\/examples.javacodegeeks.com\/author\/saurabh-arora\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/34289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/75"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=34289"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/34289\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=34289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=34289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=34289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}