技术开发 频道

使用Eclipse开发XMLBean项目


【IT168 技术文档】
 
  介质准备

  Eclipse3.12下载地址:http://www.eclipse.org/downloads/
  XMLBean2.10下载地址:http://xmlbeans.apache.org/sourceAndBinaries/index.html
  JDK1.4+或JDK1.5+下载地址:http://java.sun.com/j2se/1.5.0/download.jsp
  注:如果使用WebLogicServer,可以不用单独安装JDK,使用产品中自带的JDK即可

  Eclipse配置

  定义:
  %XMLBEAN_HOME%:XMLBean的安装目录
  %JAVA_HOME%:JDK安装目录
  建立Java项目



  由于想使用JDK1.5,所以选择5.0,为了项目管理方便,将原代码与生成的二进制文件分开存放

  一定要使用JDK而不是JRE,如果默认是JRE请重新定义


  定义自定义用户类库,并添加所有在%XMLBEAN_HOME%/lib下的Jar包



  将Eclipse调整到Resource视图,然后在根目录上添加dist(用来存放生成的jar包)和schemas(用于存放schema文件)目录


  在根目录上创建build.xml文件,并且定义ExternalTools

  指定ant脚本文件,指向刚才建立的build.xml文件

  将%XMLBEAN_HOME%/lib下的所有jar添加到classpath中





  确定使用指定的JDK

  测试

 测试

  修改build.xml

  
内容如下:
<?xml version="1.0" encoding="UTF-8" ?>
   <project name="xmlbean" default="build_all_schemas" basedir="." >
    <taskdef name="xmlbean" classname="org.apache.xmlbeans.impl.tool.XMLBean" />
    <target name="build_all_schemas" >
     <xmlbean schema="schemas"destfile="dist/Schemas.jar"
classgendir="build"srcgendir="src" javasource="1.5" /> </target> </project>
  将测试用的Schema文件(easypo.xsd)放在Schemas目录下

  内容如下:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:po="http://openuri.org/easypo" targetNamespace="http://openuri.org/easypo" elementFormDefault="qualified" > <xs:element name="purchase-order" > <xs:complexType> <xs:sequence> <xs:element name="customer" type="po:customer" /> <xs:element name="date" type="xs:dateTime" /> <xs:element name="line-item" type="po:line-item"
minOccurs
="0" maxOccurs="unbounded" /> <xs:element name="shipper" type="po:shipper"
minOccurs
="0" maxOccurs="1" /> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="customer" > <xs:sequence> <xs:element name="name" type="xs:string" /> <xs:element name="address" type="xs:string" /> </xs:sequence> <xs:attribute name="age" type="xs:int" /> <xs:attribute name="moo" type="xs:int" default="100" /> <xs:attribute name="poo" type="xs:int" fixed="200" /> </xs:complexType> <xs:complexType name="line-item" > <xs:sequence> <xs:element name="description" type="xs:string" /> <xs:element name="per-unit-ounces" type="xs:decimal" /> <xs:element name="price" type="xs:decimal" /> <xs:element name="quantity" type="xs:integer" /> </xs:sequence> </xs:complexType> <xs:complexType name="shipper" > <xs:sequence> <xs:element name="name" type="xs:string" /> <xs:element name="per-ounce-rate" type="xs:decimal" /> </xs:sequence> </xs:complexType> </xs:schema>
  执行

  显示Ant视图

  关联build.xml文件

  双击要执行的AntTask,成功后,会有些报错信息,可以忽略不计

0
相关文章