xjc.exe
Sunday Jul 01, 2007
Today I was looking some options in jdk/bin and suddenly I came across
a file name xjc.exe in JDK6. Quickly I checked the existence of this file in JDK 5.0 and JDK
1.4.2. File was not present. Goggling didn't provided too much of help
and I tried with myself :)
I just copied an XSD file from somewhere:
FileName: unknowntest.xsd
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="country">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="pop" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
and passed this XSD file into xjc option:
Usage: xjc [-options ...]
parsing a schema...
compiling a schema...
generated\Country.java
generated\ObjectFactory.java
Ah I got 2 Java files - Country.java and ObjectFactory.java
Look at these 2 files ( I am removing the documentation part of it, to make it small)
package generated;
import java.math.BigDecimal;
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 = {
"name",
"pop"
})
@XmlRootElement(name = "country")
public class Country {
@XmlElement(required = true)
protected String name;
@XmlElement(required = true)
protected BigDecimal pop;
/**
* Gets the value of the name property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getName() {
return name;
}
/**
* Sets the value of the name property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setName(String value) {
this.name = value;
}
/**
* Gets the value of the pop property.
*
* @return
* possible object is
* {@link BigDecimal }
*
*/
public BigDecimal getPop() {
return pop;
}
/**
* Sets the value of the pop property.
*
* @param value
* allowed object is
* {@link BigDecimal }
*
*/
public void setPop(BigDecimal value) {
this.pop = value;
}
}
and
objectFactory don't have too much in it. Just creating a Country class
instance. Oh so it is something cool, its making all the getter and
setter method for me, what else I need :).
Remember, such type
of methods are too much in demand when you are writing any jsp page.
So, if you are clear with the data type, just make an xsd file and xjc
will convert in into java code.
I still doubt what xjc refers for ... may be xml to java converter :)














