12.4. Java

Each implementation of XSLT that we've chosen to emphasize is described according to three basic characteristics. First, the installation is explained in sufficient detail that users unfamiliar with, for example, Java CLASSPATHs, will still be able to take advantage of the software that requires them. Second, the various special extensions added by each package are presented. Finally, any caveats or unimplemented features are noted, not as an evaluation, but as a summary of frequently discussed aspects of the software that are useful in planning how to work with XSLT stylesheets and how to utilize XSLT processing software.

In Section 12.3.1, we offer an opportunity to learn to install the JDK (Java Development Kit) that is required for most XML processing software, especially for XSLT. It is too often the case that packages come with the somewhat unhelpful line “Install JDK 1.1.6 or later” and little else. This means chasing around the Internet to find the JDK, figuring out which version to use, making sense of PATHs vs. CLASSPATHs, and often never even getting Java, let alone an XSLT processor or XSLT stylesheet, running. This book was designed to not take for granted that everyone already knows everything about Java. For those who do know the JDK, skip Section 12.3.1; for those who don't, we hope it helps, as we wrote it out of our own frustration with too much Java-related technology being taken for granted and too little help available.

12.4.1. Getting Java Going on Your Solaris/UNIX, Macintosh, or Windows Machine

The processors emphasized here all work predominantly with the JDK. Most assume or prefer JDK 1.1.6 or later, and some work best with JDK 1.2. In general, you are almost always safest with JDK 1.1.8 or later, but in many cases, XSLT processors are designed with increased convenience or simplicity if you have JDK 1.2 (also called, somewhat confusingly, Java 2). For example, Java 2 does not require the additional installation of Swing, which further simplifies the use of the GUI for Xalan, designed by Eric Lawson.

In essence, you are going to learn how to install a Java Virtual Machine, sometimes called a Java VM, or JVM. The JVM and JDK are not necessarily the same thing, and the nuances are important if you are programming in Java. They are not pivotal for XSLT. All you really need is a general idea what the JDK does on your system so that you can get the most out of your XSLT processor. In short, think of the JDK as being like your operating system.

If you work on Solaris, the JDK is an environment, so to speak, in which Java applications can run. The same thing applies to a Macintosh or Windows machine; the JDK is a “layer” on top of the basic operating system. The JDK runs like an application on top of the Mac OS (operating system) or Windows 95, 98, or NT basic OS. Then, a Java application in this case, the XSLT processor runs on top of that. If it sounds complex, don't worry; the beauty of Java is that you are largely insulated from this and your machine is insulated from crashes when you run a Java application.

It may prove worthwhile to add a little memory to your machine, because these layers do take up space, especially if the XML document instances you are transforming with your XSLT stylesheets are large. At a minimum, 64MB of RAM is needed for Windows, and realistically, not less than 128MB are required. At a minimum, the same is required for Macintosh, but realistically, unless you have a lot of time on your hands to wait while it runs, you need 128MB or more. Mac OS 7.6 or later is a bare minimum, but you should really have 8.1 or later. You can always use virtual memory, but this is going to be as slow as your hard drive already is because, of course, that's what virtual memory uses.

For Solaris and UNIX, you are usually on a shared network, so this is less of a problem, but you are going to want to carve out a little extra memory (we'll show you how) when you run the XSLT processor. If you have a Sun Ultra, for instance, don't even try to work with less than 64MB of RAM, and again, realistically, you will be need 128MB (just using swap doesn't help because, again, virtual memory is as slow as your hard drive).

Another advantage is that one Java application runs on Java for Mac, or Java for Windows, or Java for UNIX, largely transparently. That's why you will read about Java parsers or XSLT processors more than Windows or Macintosh processors; the Java XSLT processor can run on either, for the most part.

So, to get the benefits of Java and to start using XSLT processors, you will need to get the JDK that is appropriate for your machine. Once you have that “Java operating system” ready, you can run all the Java XML processing software you want. That's a great advantage of Java too; once the JVM is installed, you've instantly made a whole new world of software available to yourself much or most of which is also free!

12.4.1.1. Accessing a Java Virtual Machine

If you are on a Solaris or UNIX system, chances are there is already a JVM installed (if not, there are instructions in Section 12.3.1.2). Contact your system administrator to find out where it is on the system so you know in what directory to look for the settings described below for each XSLT processor. Usually, it will be the location of the Java classes, so you can set a Java CLASSPATH to point to them.

You can also find the JVM yourself with a little persistence. Using a command-line window (terminal, in Solaris), type java. If a set of instructions for running Java comes up, you are all set. If not, you will need to do a couple more things.

  1. Try to find the JVM by changing into your root directory. Type cd / at the command line.

  2. Test to see if there is a Java version running by typing Java-version.

  3. Type find . -name 'java' -print.

  4. Set your environment to point to the path by typing:

    setenv CLASSPATH=/java/classes/classes.zip
    

    Note that this assumes you are using csh, not ksh or Bourne shell. The path shown here may change depending on where java is on your system.

  5. If you know where your XSLT processor files are, you can do all this in one step by separating each with a colon (:) as below for an installation of XT where the XT files are all in your usr/bin directory.

    1. For pre-JDK 1.2:

      setenv CLASSPATH=/usr/bin/xt/sax.jar:/usr/bin/xt/xt:/java/classes/classes.zip
      
    2. For JDK1.2+:

      setenv CLASSPATH=/usr/bin/xt/sax.jar:/usr/bin/xt/xt:.
      
  6. You can also make this permanent if you're comfortable editing your .cshrc file; just add the following line to it (exactly as above, but with set rather than setenv, and remember that /java/classes/classes.zip is only for pre-JDK 1.2; otherwise only a “.” period is needed).

    1. For pre-JDK 1.2:

      set CLASSPATH=/usr/bin/xt/sax.jar:/usr/bin/xt/xt:/java/classes/classes.zip
      
    2. For JDK1.2+:

      set CLASSPATH=/usr/bin/xt/sax.jar:/usr/bin/xt/xt:.
      

If you work with Internet Explorer 5.0 or later (actually 4.0 or later, but we recommend 5.0), there is a JVM built in, which can be used with either Instant Saxon or the Windows version of XT. In these two cases, the Saxon or XT processor comes preconfigured to access the JVM that is part of IE. You can download IE 5.0 at http://www.microsoft.com. The instructions for using Instant Saxon or XT Windows version are quite simple once you have IE 5.0, which is free and automatically installs all you need if you follow the default settings in the installation wizard.

12.4.1.2. Setting Up a JVM on Solaris/UNIX (Linux, too)

Most of these installations are very similar, so we will generalize here. When you choose the specific package you need, detailed instructions will lead you through the particulars.

The most important thing here is to be sure you get the right version of the JVM when you download. It requires a few additional steps to work in UNIX or Solaris, but it's still quite easy and should not take more than an hour with a reliable, fast Ethernet Internet connection. If you skipped Section 12.3.1.1, reading it could save a lot of time if—and it is highly likely that this is the case—the JVM is already on your system.

If not, go to the Sun site at http://www.java.sun.com and download the JDK file (1.1.8 or later). Get the SPARC or Intel Solaris version as needed. For instance, with Java 2, you might download the Solaris SPARC file 1.2.2_05_jdk_sparc.tar.Z. Root privileges are not necessary to install or run Java.

  1. Choose a directory in which to install, such as the common /usr/local/bin or /usr/bin or /local/bin (sometimes Solaris installs work most transparently when you use /opt), and copy the files into it if they are not already there.

  2. Use uncompress 1.2.2_05_jdk_sparc.tar.Z to unzip, then use tar xvf 1.2.2_05_jdk_sparc.tar to unarchive, or untar, the file.

  3. Untarring the file creates all necessary directories and subdirectories.

  4. Set your environment permanently by changing your .cshrc file; for instance, if you are installing into /usr/bin, add the following line to your .cshrc.

    1. For pre-JDK 1.2:

      set CLASSPATH=/usr/bin/java/classes/classes.zip
      
    2. For JDK1.2+:

      set CLASSPATH=.
      

      On Windows, remember to use the semi-colon (;) and reverse slash ().

  5. If you do not want to make this permanent, you can simply set this each time with:

    1. For pre-JDK 1.2:

      setenv CLASSPATH=/usr/bin/java/classes/classes.zip
      
    2. For JDK1.2+:

      setenv CLASSPATH=.
      

You are now ready to run the XSLT processor on your Solaris, UNIX, or Linux system by augmenting this CLASSPATH with the location of the XSLT files you have chosen to use. Test the installation by typing java at the prompt, or java version to see if it's the version you thought you installed.

12.4.1.3. Installing the JDK on Windows

When you choose to run Java on Windows, you will download either one large .zip file or several small files from http://java.sun.com. Whichever you choose, follow the instructions for dealing with the multiple or single files as appropriate (it is recommended that, to avoid errors, waiting the additional time for downloading the single file is worth it). Put the downloaded file into a folder on your PC, such as c:utilities or c:java, and unzip it with WinZip (likely on your machine; otherwise, do a simple search on the Web and download it). You can double-click on the .zip file with WinZip on your system and it will open up. Then, double-click the resulting executable file and follow the auto-prompts through the installation process with the install wizard.

Once you've gone through the install, you need to add a few lines to your autoexec.bat file, which you will find by using Notepad and looking for it on the root c:directory (remember to choose “All” in the Files of Type pulldown in the Open File window). The change to PATH identifies the actual program location. CLASSPATH identifies the class file locations. If you installed the JDK to c:jdk1.2.2, program files like javac are in c:jdk1.2.2in, and the class files are in c:jdk1.2.2libclasses.zip. Add the following lines (assuming you have installed the JDK into c:java, though the wizard will often choose something like c:jdk1.2.2) to your autoexec.bat file:

PATH ......;C:jdk1.2.2in;.......
SET CLASSPATH=.

The “......” denote whatever directories are already in your PATH; be sure to separate each one with a semicolon, though no semicolon is added at the end of the line, and do not use spaces or hard returns. If you are using Windows NT, you can specify the path by going to Start, Control Panel, System, Environment. Test to see if you have been successful by typing java at a c: prompt in a DOS window (go to Start, Run, and type cmd), or to see if you have the right version running in case there was another previously installed or conflicting version type c:java version.

12.4.1.4. Installing Java on a Macintosh

Setting up Java on a Macintosh is extremely simple. You need only to run the install and all the paths for running Java will be correct. The only paths you will need to add are those for whatever XSLT software you choose.

First, get the Mac MRJ 2.2.2. Next, you need to get the Java for Mac that has JBindery. It comes with the MRJ SDK. You can find the MRJ 2.2 SDK for free at http://developer.apple.com/java/text/download.html#sdk (it takes a few minutes from home, less on Ethernet). Macintosh Runtime for Java Software Development Kit 2.1 is fine if you have it. Now install it by double-clicking the icon, following all the automatic presets. When it's done, you will see the MRJ SDK 2.1 directory on your hard drive, inside that is a folder called Tools, and one called Application Builders. It is inside the Application Builders where you will find the JBindery folder (if not, remove MRJ, reinstall with the Custom option, and select all components).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.8.110