A picture of Rob

Robert Capra
http://www.ils.unc.edu/~rcapra


Home |  Publications |  Research |  Teaching |  Notes


Installing and Using Xalan with JDK6 in Linux RHEL5

06-Mar-2008

Xalan is an Apache project XSLT processor. There are two main implementations of Xalan, one written in Java and another in C++. I'll be covering only the Java version (Xalan-J) here.

The Problem

Download, install, and use Xalan-J on a RHEL 5 platform.

The Solution

I previously installed Sun's JDK rather rather than using the GNU Complier for Java (GCJ) which can be installed by default with RHEL5. See my Notes on Tomcat Solr and RHEL5 for details of installing Sun's Java and using jpackage to manage multiple java installations on one RHEL5 machine.

Download Xalan binaries
The Xalan-J site has information about where to download the latest release. I got the binary distribution xalan-j_2_7_1-bin.zip from ibiblio. The binaries (e.g. jar files) can be used with an existing Java installation without having to download and compile the source code (.java) files.

Install Xalan
How you "install" Xalan depends on your goals. If you are installing Xalan for your own personal use on a multi-user system, you can unzip the binaries in your own account and point your CLASSPATH to them. If you are administering a RHEL5 system and want to install Xalan so that other users of the system can access it, then you may want to put it in a Java extension directory.

CLASSPATH approach
Unzip the xalan binaries into a directory. In this example, I'll use /home/rcapra/javalib:

cd /home/rcapra/javalib
unzip xalan-j_2_7_1-bin.zip
			
This should create a subdirectory called xalan-j_2_7_1 that will contain the files you need to run Xalan.
Four files need to be included in your CLASSPATH:
xalan.jar
xercesImpl.jar
xml-apis.jar
serializer.jar.
			
Once these are in your CLASSPATH, you should be ready to try it out (see the section below on "Running Xalan").

Java Extension Directory
I haven't worked with the Java Extension Mechanism much, but I believe that this is a valid use for it. If readers know otherwise, please let me know. In this approach, unzip the downloaded binaries as described in the "CLASSPATH approach" section and then copy the four jar files into the Java extension directory. For Linux systems, this directory is /usr/java/packages/lib/ext. Note that you can also use a version specific directory, $JRE_HOME/jre/lib/ext. The difference is that the /usr/java/packages/lib/ext should be available to all Java installations where the version specific directory only makes the extension available for that extension. I've only tried the non-version specific method, and on my RHEL5 system, I had to create the directory and then copy the jar files:

mkdir /usr/java/packages/lib/ext
cp /home/rcapra/javalib/xalan-j_2_7_1/*.jar /usr/java/packages/lib/ext
			
Java should now find the jar files.

Another approach
The Xalan FAQ suggests using the Java Endorsed Standards Override Mechanism: http://xml.apache.org/xalan-j/faq.html#faq-N100EF. This section of the FAQ also claims that using the CLASSPATH may not work to override the packaged version of Xalan, but I was able to use the CLASSPATH as described above using JDK6.

Running Xalan
The following command will run Xalan from the command line:

java com.sun.org.apache.xalan.internal.xslt.Process -IN in.xml -XSL in.xsl -OUT out.xml
			
There is additional information on running Xalan from the command line on the Xalan website page, http://xml.apache.org/xalan-j/commandline.html

False Starts

Since JDK 1.4, Xalan has been packaged with Sun's JDK. So why download and install the most recent version when there is one already included with the JDK? I only planned to do basic XLST processing, so I figured that the version included with the JDK would be fine.

To use the version packaged with the JDK, there is a slightly different path to the Process class.

com.sun.org.apache.xalan.internal.xslt.Process
			
However, trying:
java com.sun.org.apache.xalan.internal.xslt.Process -IN in.xml -XSL in.xsl -OUT out.xml
			
Gave the following error:
Exception in thread "main" java.lang.NoSuchMethodError: main
			
It turns out that there is a bug that has been around since JDK 1.4 (and still appears to be present in JDK 6) that there is no "main" for the Process class. According to this posting, the main class is incorrectly _main.

An obvious workaround (which I have seen mentioned in the post above and elsewhere) would be to write a wrapper class. I decided that once I wasn't getting the packaged version "for free" so to speak, that I might as well download and install the latest release.

Links/References

  1. Apache Xalan-J Download Information
  2. Java Tutorial Trail on The Extension Mechanism


Home |  Publications |  Research |  Teaching |  Notes


Prepared by r c a p r a 3 [at] u n c [dot] e d u
Last modified: March 07 2008 01:20:33
Copyright 2000-2008 by Robert G. Capra III