時(shí)間:2006-05-25 作者:牛秀元 瀏覽次數(shù): 273 本文關(guān)鍵字:XMLBean,?XML,?Eclipse |
|

- 介質(zhì)準(zhǔn)備
- Eclipse配置
- 測(cè)試
- 修改build.xml
-
將測(cè)試用的Schema文件(easypo.xsd)放在Schemas目錄下
內(nèi)容如下:
-
執(zhí)行
顯示Ant視圖
關(guān)聯(lián)build.xml文件
雙擊要執(zhí)行的AntTask,成功后,會(huì)有些報(bào)錯(cuò)信息,可以忽略不計(jì)
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,可以不用單獨(dú)安裝JDK,使用產(chǎn)品中自帶的JDK即可
定義:
%XMLBEAN_HOME%:XMLBean的安裝目錄
%JAVA_HOME%:JDK安裝目錄
建立Java項(xiàng)目
由于想使用JDK1.5,所以選擇5.0,為了項(xiàng)目管理方便,將原代碼與生成的二進(jìn)制文件分開存放
一定要使用JDK而不是JRE,如果默認(rèn)是JRE請(qǐng)重新定義
定義自定義用戶類庫(kù),并添加所有在%XMLBEAN_HOME%/lib下的Jar包
將Eclipse調(diào)整到Resource視圖,然后在根目錄上添加dist(用來存放生成的jar包)和schemas(用于存放schema文件)目錄
在根目錄上創(chuàng)建build.xml文件,并且定義ExternalTools
指定ant腳本文件,指向剛才建立的build.xml文件
將%XMLBEAN_HOME%/lib下的所有jar添加到classpath中
確定使用指定的JDK
內(nèi)容如下:
<?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>
<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>

?作者簡(jiǎn)介 | |
![]() 牛秀元 |
牛秀元是(dev2dev ID: Guru),BEA系統(tǒng)(中國(guó))有限公司技術(shù)顧問,曾任Business Objests技術(shù)顧問,合力思軟件公司技術(shù)顧問 |