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

标签: jdk xjc 命令 | 发表时间:2013-06-09 21:48 | 作者:Apache012
出处:http://blog.csdn.net
xcj命令有schema文件生成java实体类
1、使用方法
   xjc fileName.xsd -d 生成java实体类的目录 -p 生成的包名
2. eg: xjc catalog.xsd -d -p com.xjc.bean

3、其他的参数

  -httpproxy <proxy> :  set HTTP/HTTPS proxy. Format is [user[:password]@]proxyH
ost:proxyPort
  -httpproxyfile <f> :  Works like -httpproxy but takes the argument in a file t
o protect password
  -classpath <arg>   :  specify where to find user class files
  -catalog <file>    :  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 <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 <FILE>    :  generate the episode file for separate compilation

4. 例如

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

   catalog.xsd文件生成java实体类

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
		targetNamespace="http://www.itcast.org/catalog" 
		xmlns:tns="http://www.itcast.org/catalog" 
		elementFormDefault="qualified">
		<element name="catalog">
			<complexType>
				<sequence>
					<element name="infoNode" type="tns:infoNode" minOccurs="0" maxOccurs="unbounded"></element>
					<element ref="tns:catalog" minOccurs="0" maxOccurs="unbounded"></element>
				</sequence>
				<attribute name="id" use="required" type="string"></attribute>
				<attribute name="title" use="required" type="string"></attribute>
			</complexType>
		</element>
		<complexType name="infoNode">
			<attribute name="id" use="required" type="string"></attribute>
			<attribute name="infonodeid" use="required" type="string"></attribute>
		</complexType>
</schema>
5、生成的4个类
     

//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
// 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;


/**
 * <p>Java class for anonymous complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * <complexType>
 *   <complexContent>
 *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       <sequence>
 *         <element name="infoNode" type="{http://www.itcast.org/catalog}infoNode" maxOccurs="unbounded" minOccurs="0"/>
 *         <element ref="{http://www.itcast.org/catalog}catalog" maxOccurs="unbounded" minOccurs="0"/>
 *       </sequence>
 *       <attribute name="id" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
 *       <attribute name="title" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
 *     </restriction>
 *   </complexContent>
 * </complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "infoNode",
    "catalog"
})
@XmlRootElement(name = "catalog")
public class Catalog {

    protected List<InfoNode> infoNode;
    protected List<Catalog> catalog;
    @XmlAttribute(name = "id", required = true)
    protected String id;
    @XmlAttribute(name = "title", required = true)
    protected String title;

    /**
     * Gets the value of the infoNode property.
     * 
     * <p>
     * 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 <CODE>set</CODE> method for the infoNode property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getInfoNode().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link InfoNode }
     * 
     * 
     */
    public List<InfoNode> getInfoNode() {
        if (infoNode == null) {
            infoNode = new ArrayList<InfoNode>();
        }
        return this.infoNode;
    }

    /**
     * Gets the value of the catalog property.
     * 
     * <p>
     * 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 <CODE>set</CODE> method for the catalog property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getCatalog().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link Catalog }
     * 
     * 
     */
    public List<Catalog> getCatalog() {
        if (catalog == null) {
            catalog = new ArrayList<Catalog>();
        }
        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 <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
// 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;


/**
 * <p>Java class for infoNode complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * <complexType name="infoNode">
 *   <complexContent>
 *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       <attribute name="id" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
 *       <attribute name="infonodeid" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
 *     </restriction>
 *   </complexContent>
 * </complexType>
 * </pre>
 * 
 * 
 */
@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 <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
// 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. 
 * <p>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 <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
// 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;




作者:Apache012 发表于2013-6-9 21:48:49 原文链接
阅读:97 评论:0 查看评论

相关 [jdk xjc 命令] 推荐:

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

- - CSDN博客研发管理推荐文章
xcj命令有schema文件生成java实体类.    xjc fileName.xsd -d 生成java实体类的目录 -p 生成的包名.    catalog.xsd文件生成java实体类. 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.

常用的JDK自带命令行工具

- - 四火的唠叨
文章系本人原创,转载请保持完整性并注明出自 《四火的唠叨》. 在 这里可以找得到这些工具的列表,虽然官网上免责声明为 “The tools described in this section are unsupported and experimental in nature and should be used with that in mind.

Sun JDK 1.6内存管理

- 小丑鱼 - 淘宝JAVA中间件团队博客
分为使用篇、调优篇和实现篇三个部分,使用篇为填鸭式,调优篇为pattern式,实现篇为启发式,三个PPT的目标为:. 1.掌握Sun JDK的内存区域的划分;. 2.掌握Sun JDK垃圾收集器的使用方法和触发时机;. 4.掌握一些基本的GC调优的方法;. 5.了解自动内存管理的常见实现方法,以及Sun JDK所做的优化.

JDK自带监控工具

- - ITeye博客
         系统在生产运行过程中最重要的工作莫过于监控与问题的处理,监控是预防问题产生很重要的手段. 在监控过程中可以发现那些模块或进程出现了问题,出现问题后会及时通知问题负责人.         实现监控的手段非常多,有系统级别监控系统,也有监控小工具等等. Java 就已经自带了一些监控工具,可以不借助外部软件的情况下简单、快速查看相应监控信息.

JDK动态代理机制

- - CSDN博客编程语言推荐文章
    代理模式有两种,一种是静态代理,这种方式需要为每一个被代理类写一个代理类,显示比较麻烦. 还一种是动态代理,动态代理实现方式一般有两种,JDK动态代理与CGLIB动态代理,这里说一下对JDK动态代理的理解.     JDK动态代理最核心的就类就是java.lang.reflect.Proxy,可调用Proxy.newInstance(..)生成动态代理.

JAVA之JDK动态代理

- - Java - 编程语言 - ITeye博客
在Java的java.lang.reflect包下提供了一个Proxy类和一个InvocationHandler接口,通过这个类和接口,可以生成JDK动态代理类或动态代理对象. Proxy提供了用于创建动态代理类和代理对象的静态方法,它也是所有动态代理类的父类,如果在程序中为一个或多个接口动态的生成实现类,就可以使用Proxy来创建动态代理类,.

赵雅智_Java JDK 5.0 内省

- - CSDN博客推荐文章
开发框架时,经常需要使用java对象的属性来封装程序的数据,每次都使用反射技术完成此类操作过于麻烦. 所以sun公司开发了一套API,专门用于操作java对象的属性. 什么是Java对象的属性和属性的读写方法?. 内省访问JavaBean属性的两种方式:. 通过PropertyDescriptor类操作Bean的属性.

Spring AOP 代理机制 JDK&CGLIB

- - 开源软件 - ITeye博客
Spring AOP使用JDK动态代理或者CGLIB来为目标对象创建代理. (建议优先使用JDK的动态代理). 如果被代理的目标对象实现了至少一个接口,则会使用JDK动态代理. 所有该目标类型实现的接口都将被代理. 若该目标对象没有实现任何接口,则创建一个CGLIB代理. 如果你希望强制使用CGLIB代理,(例如:希望代理目标对象的所有方法,而不只是实现自接口的方法) 那也可以.

Hadoop 2.7.0 发布,不再支持 JDK 6

- - 开源中国社区最新新闻
Apache Hadoop 2.7.0 发布,包括大量显著改进,值得关注的改进如下:. 此版本不再支持 JDK 6 运行时,仅支持 JDK 7+. 还有一些重要的问题需要通过测试,用于生产环境的用户请等待 2.7.1/2.7.2. 支持 Windows Azure 存储 —— Blob. 自动分享,全局缓存 YARN 本地化资源(测试阶段).

动态代理双剑客--JDK Proxy与CGLIB

- - CSDN博客推荐文章
研究过设计模式的同胞们都知道代理模式可以有两种实现方案:. 1.接口实现(或继承抽象类). 都可以通过Proxy控制对Target的访问. “接口实现”的方式更加灵活,代理类可以代理所有实现了ISubject接口的类;. “继承父类”的方式代理类只能代理它的父类,因为java中只支持单继承. 如果Target有直接接口,那么这两种方式都可以;.