使用jdk的xjc命令由schema文件生成相应的实体类

xcj命令有schema文件生成java实体类
1、使用方法
   xjc fileName.xsd -d 生成java实体类的目录 -p 生成的包名
2. eg: xjc catalog.xsd -d -p com.xjc.bean

3、其他的参数

  -httpproxy :  set HTTP/HTTPS proxy. Format is [user[:password]@]proxyH
ost:proxyPort
  -httpproxyfile :  Works like -httpproxy but takes the argument in a file t
o protect password
  -classpath   :  specify where to find user class files
  -catalog    :  specify catalog files to resolve external entity referen
ces
                        support TR9401, XCatalog, and OASIS XML Catalog format.
  -readOnly          :  generated files will be in read-only mode
  -npa               :  suppress generation of package level annotations (**/pac
kage-info.java)
  -no-header         :  suppress generation of a file header with timestamp
  -target (2.0|2.1)  :  behave like XJC 2.0 or 2.1 and generate code that doesnt
 use any 2.2 features.
  -encoding :  specify character encoding for generated source files
  -enableIntrospection :  enable correct generation of Boolean getters/setters t
o enable Bean Introspection apis
  -contentForWildcard  :  generates content property for types with multiple xs:
any derived elements
  -xmlschema         :  treat input as W3C XML Schema (default)
  -relaxng           :  treat input as RELAX NG (experimental,unsupported)
  -relaxng-compact   :  treat input as RELAX NG compact syntax (experimental,uns
upported)
  -dtd               :  treat input as XML DTD (experimental,unsupported)
  -wsdl              :  treat input as WSDL and compile schemas inside it (exper
imental,unsupported)
  -verbose           :  be extra verbose
  -quiet             :  suppress compiler output
  -help              :  display this help message
  -version           :  display version information
  -fullversion       :  display full version information

Extensions:
  -Xinject-code      :  inject specified Java code fragments into the generated
code
  -Xlocator          :  enable source location support for generated code
  -Xsync-methods     :  generate accessor methods with the 'synchronized' keywor
d
  -mark-generated    :  mark the generated code as @javax.annotation.Generated
  -episode    :  generate the episode file for separate compilation

4. 例如

xjc catalog.xsd -d . -p cn.heima.catalog.schema.entity

   catalog.xsd文件生成java实体类



		
			
				
					
					
				
				
				
			
		
		
			
			
		
5、生成的4个类
     

//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 
// See http://java.sun.com/xml/jaxb 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2013.06.09 at 09:28:16 PM CST 
//


package cn.heima.catalog.schema.entity;

import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;


/**
 * 

Java class for anonymous complex type. * *

The following schema fragment specifies the expected content contained within this class. * *

 * 
 *   
 *     
 *       
 *         
 *         
 *       
 *       
 *       
 *     
 *   
 * 
 * 
* * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "infoNode", "catalog" }) @XmlRootElement(name = "catalog") public class Catalog { protected List infoNode; protected List catalog; @XmlAttribute(name = "id", required = true) protected String id; @XmlAttribute(name = "title", required = true) protected String title; /** * Gets the value of the infoNode property. * *

* This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a set method for the infoNode property. * *

* For example, to add a new item, do as follows: *

     *    getInfoNode().add(newItem);
     * 
* * *

* Objects of the following type(s) are allowed in the list * {@link InfoNode } * * */ public List getInfoNode() { if (infoNode == null) { infoNode = new ArrayList(); } return this.infoNode; } /** * Gets the value of the catalog property. * *

* This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a set method for the catalog property. * *

* For example, to add a new item, do as follows: *

     *    getCatalog().add(newItem);
     * 
* * *

* Objects of the following type(s) are allowed in the list * {@link Catalog } * * */ public List getCatalog() { if (catalog == null) { catalog = new ArrayList(); } return this.catalog; } /** * Gets the value of the id property. * * @return * possible object is * {@link String } * */ public String getId() { return id; } /** * Sets the value of the id property. * * @param value * allowed object is * {@link String } * */ public void setId(String value) { this.id = value; } /** * Gets the value of the title property. * * @return * possible object is * {@link String } * */ public String getTitle() { return title; } /** * Sets the value of the title property. * * @param value * allowed object is * {@link String } * */ public void setTitle(String value) { this.title = value; } }

//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 
// See http://java.sun.com/xml/jaxb 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2013.06.09 at 09:28:16 PM CST 
//


package cn.heima.catalog.schema.entity;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;


/**
 * 

Java class for infoNode complex type. * *

The following schema fragment specifies the expected content contained within this class. * *

 * 
 *   
 *     
 *       
 *       
 *     
 *   
 * 
 * 
* * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "infoNode") public class InfoNode { @XmlAttribute(name = "id", required = true) protected String id; @XmlAttribute(name = "infonodeid", required = true) protected String infonodeid; /** * Gets the value of the id property. * * @return * possible object is * {@link String } * */ public String getId() { return id; } /** * Sets the value of the id property. * * @param value * allowed object is * {@link String } * */ public void setId(String value) { this.id = value; } /** * Gets the value of the infonodeid property. * * @return * possible object is * {@link String } * */ public String getInfonodeid() { return infonodeid; } /** * Sets the value of the infonodeid property. * * @param value * allowed object is * {@link String } * */ public void setInfonodeid(String value) { this.infonodeid = value; } }
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 
// See http://java.sun.com/xml/jaxb 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2013.06.09 at 09:28:16 PM CST 
//


package cn.heima.catalog.schema.entity;

import javax.xml.bind.annotation.XmlRegistry;


/**
 * This object contains factory methods for each 
 * Java content interface and Java element interface 
 * generated in the cn.heima.catalog.schema.entity package. 
 * 

An ObjectFactory allows you to programatically * construct new instances of the Java representation * for XML content. The Java representation of XML * content can consist of schema derived interfaces * and classes representing the binding of schema * type definitions, element declarations and model * groups. Factory methods for each of these are * provided in this class. * */ @XmlRegistry public class ObjectFactory { /** * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: cn.heima.catalog.schema.entity * */ public ObjectFactory() { } /** * Create an instance of {@link Catalog } * */ public Catalog createCatalog() { return new Catalog(); } /** * Create an instance of {@link InfoNode } * */ public InfoNode createInfoNode() { return new InfoNode(); } }


//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 
// See http://java.sun.com/xml/jaxb 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2013.06.09 at 09:28:16 PM CST 
//

@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.itcast.org/catalog", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package cn.heima.catalog.schema.entity;




你可能感兴趣的:(javaweb)