The XJ distribution consists of two .zip archives. The xj-bin-1.0.zip archive contains all the files needed to compile and run XJ programs on the command line, some sample XJ programs, and the PDF version of this manual. Appendix G describes the contents of this archive in greater detail. The xj-src-1.0.zip archive contains modifications that were made to the Eclipse JDT compiler, on which the XJ compiler is based (it is not essential to download this archive).
The XJ compiler and runtime system require the presence of a Java 1.4 Runtime Environment (JRE). In particular, XJ assumes that the runtime environment includes a Java API for XML processing (JAXP [Mordani and Boag 2002])-compliant XML parser and the Xalan XSLT engine, both of which are distributed with standard Java 1.4 runtime environments.
We have tested the XJ system with both the IBM and the Sun JREs, under Windows/CMD, Cygwin, and Linux -- if there are problems, please file a bug report (see section 1.3).
To install the XJ distribution, extract the downloaded zip. In this document, we will refer to the XJJDT/ subdirectory that will be created by the extraction as $XJ_HOME (Note that there is no need to actually set an environment variable XJ_HOME). You may wish to add $XJ_HOME/bin to your PATH environment variable to avoid specifying the full path to the XJ scripts each time.
The XJ distribution provides two executables: "xj" and "xjc", by analogy to "java" and "javac". Both of these executables use the following mechanisms to discover the location of the JRE installation on a machine:
XJ programs can be compiled by running "xjc <filename>". The XJ compiler recognizes files with either the ".java" and the ".xj" extensions. Most of the options available in a standard javac compiler are available in the XJ compiler xjc. For a full list of available options, run "xjc -help". For example, one can specify additional classpath entries by supplying one or more "-cp <directory_or_jarfile>" options to xjc (these options are cumulative), or by setting the $CLASSPATH environment variable. As in Java, the classpath entries are used to find classes, packages, and other resources. In addition, the classpath entries are used to locate XML Schemas referred to by a program (§3.1.1).
For example (on Linux), to compile the class Totals provided in the samples directory of the distribution:
|
[$XJ_HOME/samples]$
export JAVA_HOME=/opt/IBMJava2-141/
[$XJ_HOME/samples]$ ../bin/xjc com/ibm/xj/samples/totals/Totals.xj [$XJ_HOME/samples]$ |
In the example, the user sets the JAVA_HOME
environment variable to refer
to the appropriate directory, and then compiles the XJ class Totals.xj.
Note that successful compilation should produce no output.
By default, xjc places generated class files in the same directory as the source that is compiled (as does javac). This setting can be changed by using the "-d <directory>" xjc option. The generated class files are as defined by Java and can be executed on any Java Virtual Machine.
All references in a program to XML Schema constructs are removed in the compilation process and are not present in the generated class file. As a result, separate compilation of XJ classes may not work properly. When compiling an XJ class that refers to another class, B, the XJ compiler executes the following algorithm:
While the XJ compiler attempts to discover and recompile all necessary XJ classes, it is best to recompile all XJ classes that are part of a program explicitly by passing them as arguments to xjc.
XJ programs are compiled to standard Java class files that can be executed on any Java Virtual Machine. To execute properly, these classes require certain JARs (corresponding to the XJ runtime system) to be in the classpath at runtime. The "xj" executable invokes "java" with the appropriate classpath settings. Run "xj -help" for a list of available options.
For example (on Linux), to run the Totals class compiled in the previous step, one invokes the xj executable with the appropriate arguments.
|
[$XJ_HOME/samples]$
../bin/xj com.ibm.xj.samples.totals.Totals com/ibm/xj/samples/totals/chart.xml
Total Sales 1998 72.0 1999 79.0 2000 88.0 <?xml version="1.0" encoding="UTF-8"?> <sales unit="GBP">430.2</sales> Grand Total: 239.0 [$XJ_HOME/samples]$ |
![[*]](footnote.png)