Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerating java classes using maven-jaxb2-plugin
    text
    copied!<p>I am very new to Jaxb and this maven-jaxb2 plugin </p> <p>Here is my .xsd file :</p> <pre class="lang-xml prettyprint-override"><code>&lt;xs:element name="user" type="user" /&gt; &lt;xs:element name="userList" type="userList" /&gt; &lt;xs:complexType name="user"&gt; &lt;xs:all&gt; &lt;xs:element name="id" type="xs:long" minOccurs="0" /&gt; &lt;xs:element name="name" type="xs:string" /&gt; &lt;xs:element name="registrationDate" type="xs:dateTime" /&gt; &lt;/xs:all&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="userList"&gt; &lt;xs:sequence&gt; &lt;xs:element name="user" type="user" minOccurs="0" maxOccurs="unbounded" /&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; </code></pre> <p>Here is my .xjb file :</p> <pre class="lang-xml prettyprint-override"><code>&lt;!-- Annotate @XmlRootElement Annotation for all the classes, that matches in the .xsd with complexType --&gt; &lt;jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema"&gt; &lt;jaxb:bindings node="xs:complexType['1'='1']" multiple="true" required="false"&gt; &lt;annox:annotate&gt; &lt;annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="user" /&gt; &lt;/annox:annotate&gt; &lt;/jaxb:bindings&gt; &lt;/jaxb:bindings&gt; </code></pre> <p>and when it generates it gives the java class somewhat like :</p> <pre class="lang-java prettyprint-override"><code>XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "user", propOrder = { }) @Entity @XmlRootElement(name = "${@name}") @Table(schema = "schemaName", uniqueConstraints = { }, name = "user_") public class User implements Serializable, ToString { private final static long serialVersionUID = 1L; protected Long id; </code></pre> <p>where it should give name = object name such as here "user" I know if I write in bindings like this it will genearate </p> <pre class="lang-xml prettyprint-override"><code>&lt;jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema"&gt; &lt;jaxb:bindings node="xs:complexType[@name='user']"&gt; &lt;annox:annotate&gt; &lt;annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="user" /&gt; &lt;/annox:annotate&gt; &lt;/jaxb:bindings&gt; &lt;jaxb:bindings node="xs:complexType[@name='userList']"&gt; &lt;annox:annotate&gt; &lt;annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="userList" /&gt; &lt;/annox:annotate&gt; &lt;/jaxb:bindings&gt; &lt;/jaxb:bindings&gt; &lt;/jaxb:bindings&gt; </code></pre> <p>but i dont want to repeat the same code for user and userlist is there any way I can do by annotations or defining regular expression. Please suggest some way.</p> <p>I just wanted to know what to write in this code </p> <pre class="lang-xml prettyprint-override"><code>&lt;annox:annotate&gt; &lt;annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="user" /&gt; &lt;/annox:annotate&gt; </code></pre> <p>so that when it creates user class it show @xmlRootElement(name='user') and similary for other class @xmlRootElement(name='userList') ans similarly for others.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload