The code examples are contained in four directories:
What will I need to build the examples?
You will need a Java development environment, such as Sun's Software Development Kit (SDK). The SDK is freely available at http://java.sun.com/j2se for Win32 and Solaris. Linux versions are available at several popular Linux sites. For the CORE examples, you will need a DOM implementation. Apace Xerces or Sun JAXP are satisfactory. JDOM examples require classes available at http://www.jdom.org. The classes needed for the JAXB example can be found at http://java.sun.com/xml/jaxb/index.html. The XMLServer will require a servlet container and JDOM. Tomcat is a high quality servlet/JSP container freely available from Apache. Other servlet containers can also be used.
What is Jikes?
Jikes is a fast Java compiler freely available from IBM. Remember that you will still need the standard runtime class libraries shipped with Suns Java 2 SDK. Read the Jikes FAQ for detailed information on how to setup and use Jikes.
How do I compile and test the CORE examples?
First change directories to the core directory. You can compile all of the core examples using one command:
javac -d .. -classpath ..;c:\xerces-2_0_0_beta\xerces.jar *.java
This assumes you have downloaded Xerces into c:\xerces-2_0_0_beta. If you download a different version or install Xerces in a different directory, adjust the path to xerces.jar appropriately in the command above. This will compile all source code in the current directory and place all compiled class files one directory up. The default rule in the supplied Makefile does the same thing.
Each of the core examples can executed from the source directory as follows:
SimpleWalker:
java -classpath ..;c:\xerces-2_0_0_beta\xerces.jar com.madhu.xml.SimpleWalker <input-xml-file>
DocBuilder:
java -classpath ..;c:\xerces-2_0_0_beta\xerces.jar com.madhu.xml.DocBuilder <directory-name> <output-xml-file>
IteratorApp:
java -classpath ..;c:\xerces-2_0_0_beta\xerces.jar com.madhu.xml.IteratorApp <input-xml-file>
RangeApp:
java -classpath ..;c:\xerces-2_0_0_beta\xerces.jar com.madhu.xml.RangeApp <input-xml-file>
There are rules in the Makefile for executing each app as well. Inspect the Makefile for details.
How do I compile and test the JDOM example?
First change directories to the JDOM directory. You can compile all JDOM examples using one command:
javac -d .. -classpath ..;c:\jdom-b7\lib\xerces.jar;c:\jdom-b7\build\jdom.jar *.java
This assumes you have downloaded and installed JDOM into c:\jdom-b7. If you download a different version or install JDOM in a different directory, adjust the path to jdom.jar appropriately in the command above. This will compile all source code in the current directory and place all compiled class files one directory up. The default rule in the supplied Makefile does the same thing.
Each of the core examples can executed from the source directory as follows:
JDOMParse:
java -classpath ..;c:\jdom-b7\lib\xerces.jar;c:\jdom-b7\build\jdom.jar com.madhu.xml.JDOMParse <xml-input-file>
JDOMCreate:
java -classpath ..;c:\jdom-b7\lib\xerces.jar;c:\jdom-b7\build\jdom.jar com.madhu.xml.JDOMCreate
How do I build and compile the JAXB example?
Building the JAXB example is a two step process. First, you must create the binding classes, like this:
java -classpath c:\jaxb-1.0-ea\lib\jaxb-xjc-1.0-ea.jar com.sun.tools.xjc.Main -d xjcdest -roots <input-xml-file> <input-xml-file-dtd>
This assumes you have downloaded and installed JAXB into c:\jaxb-1.0-ea. If you download a different version or install JAXB in a different directory, adjust the path to jaxb-xjc-1.0-ea.jar appropriately in the command above. This will create four source files and place them in the directory xjcdest.
Next, you must compile all source files like this:
javac -d . -classpath .;c:\jaxb-1.0-ea\lib\jaxb-rt-1.0-ea.jar *.java xjcdest\*.java
This will compile all source files from the current directory and the generated source files in the xjcdest directory and places all compiled class files in the current directory. If you use Jikes to compile, you might get a warning, but that's OK.
To run the example, use this command:
java -classpath .;c:\jaxb-1.0-ea\lib\jaxb-rt-1.0-ea.jar LibraryApp
How do I build and test the XMLServer example?
The XMLServer example requires a servlet container, such as Apache Tomcat. If you use Tomcat, copy the xmlserver directory to the webapps directory (under Tomcat install directory). The example alse requires JDOM. Place jdom.jar (probably in c:\jdom-b7\build) in the xmlserver\Web-inf\lib directory. Change directories to the src (source) directory and compile all classes like this:
javac -d ..\classes -classpath ..\classes;c:\jakarta-tomcat-4.0.1\common\lib\servlet.jar;..\lib\jdom.jar *.java
The XMLServer example reads data from a relational database using JDBC. You will need a database, such as Microsoft Access or MySQL. The example uses ODBC to connect to an Access database with DSN worldfactbook. You can use this DSN if you plan to use an ODBC data source. Alternatively, you can adjust the JDBC url in the source to point to your database. Consult the documentation for you JDBC driver for details on url format.
Once the data source is set up, you can test the server. A sample web form is supplied for testing. If you followed the steps above using Tomcat, start Tomcat and enter the following URL in a web browser (MS IE will work for XML display):
http://localhost:8080/xmlserver/index.html
This should display a web form with a single text entry field for the query. If not, check to make sure your web server is running and is operating on the correct port. Tomcat defaults to port 8080.
Enter a simple select query into the text field and press submit. If all goes well, you should see XML representing the result set.