介質準備
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包
把xmlSchema檔案加入到工程中,例如加入hello.xsd.
<? xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
< xs:schema targetNamespace ="http://xmlbeans.apache.org/samples/template/sampletemplate"
xmlns:xs ="http://www.w3.org/2001/XMLSchema"
elementFormDefault ="qualified" >
< xs:element name ="hello" >
< xs:complexType >
< xs:sequence >
< xs:element name ="name" type ="xs:string" maxOccurs ="unbounded" />
</ xs:sequence >
</ xs:complexType >
</ xs:element >
</ xs:schema >
把ANT檔案加入到工程中,例如:
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
< project name ="SampleTemplate" default ="build" >
< property environment ="env" />
< path id ="SampleTemplate.path" >
< path refid ="xmlbeans.path" />
< fileset dir ="build/lib" includes ="*.jar" />
< pathelement path ="build/classes" />
</ path >
< target name ="init" depends = "clean" >
< property name ="xmlbeans.home" value ="${env.XMLBEANS_HOME}" />
< echo message ="xmlbeans.home: ${xmlbeans.home}" />
<!-- check for xbean.jar from binary distribution -->
< available
property ="xmlbeans.lib"
value ="${xmlbeans.home}/lib"
file ="${xmlbeans.home}/lib/xbean.jar" />
<!-- check for xbean.jar compiled from source -->
< available
property ="xmlbeans.lib"
value ="${xmlbeans.home}/build/lib"
file ="${xmlbeans.home}/build/lib/xbean.jar" />
< fail message ="Set XMLBEANS_HOME in your enviornment."
unless ="xmlbeans.lib" />