<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="about" page="gettingstarted" subpage="gettingstartedjava"/>
      <!--
           Generated at 2010-10-29T18:20:48.427+01:00--><title>Saxonica: XSLT and XQuery Processing: Getting started with Saxon on the Java platform</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title"
            content="Saxonica: XSLT and XQuery Processing: Getting started with Saxon on the Java platform"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>Getting started with Saxon on the Java platform</h1>
      <p>Saxon doesn't come with a graphical user interface: it's designed to be integrated into
other tools and applications. You will therefore start by using it from the operating system
command line. On Windows, you may want to install a text editor such as <code>jEdit</code>
that offers a more friendly command line than the standard DOS console provided by Microsoft.
However, if you're not comfortable running applications from the command line, you might like to try
the open-source <a href="http://kernowforsaxon.sourceforge.net/" class="bodylink">Kernow</a> product
from Andrew Welch. This installs Saxon for you.</p>
      <ol>
         <li content="para">
            <p>Ensure that Java is installed. This must be Java JDK 1.5 (also known as J2SE 5.0) or later.
From version 9.2, Saxon will no longer run with JDK 1.4 or earlier releases. To check that Java
is installed, try typing <code>java -version</code> at the command prompt. If it is not installed,
or if you have an older version, you can get the software from 
<a href="http://java.sun.com" class="bodylink">java.sun.com</a>.</p>
         </li>
         <li content="para">
            <p>Download the Saxon software (you will typically start with the open-source version) from
<a href="http://sourceforge.net/project/showfiles.php?group_id=29872"
                  class="bodylink">SourceForge</a>.</p>
         </li>
         <li content="para">
            <p>The software comes as a zip file. Unzip it into a suitable directory, for example
<code>c:\saxon</code>.</p>
         </li>
         <li>
            <p>To check that the software is working, try running a simple query from the command line,
as follows. The filename after the "-cp" flag should match the location where
you installed the software. The file will be called saxon9he.jar for Saxon Home Edition, saxon9pe.jar
for the Professional Edition, or saxon9ee.jar for the Enterprise Edition:</p>
            <p><b>java -cp c:\saxon\saxon9he.jar net.sf.saxon.Query -t -qs:current-date()</b></p>
            <p>Here <b>java</b> tells the operating system to run the Java virtual machine; the filename
after <b>-cp</b> is known as the classpath, and tells Java where to find the Saxon application
software; <b>net.sf.saxon.Query</b> is the Saxon entry point for the XQuery processor;
the option <b>-t</b> tells Saxon to report what it is doing on the console; and the option
<b>-qs:current-date()</b> tells Saxon to run the simple query <code>current-date()</code>, which
returns the current date and displays the result on the console.</p>
            <p>If this doesn't work, there are three possible reasons: the operating system can't find the Java
software; Java can't find the Saxon software; or Saxon has been invoked, but has failed to run your query. The error
message should give you a clue which of these is the case.</p>
         </li>
         <li content="para">
            <p>As a first-time user, you will probably want to install the sample applications.
These are packaged together with a copy of this documentation and Saxon-B source code
in the file <code>saxon-resources9-n.zip</code>. This can be downloaded from either the
SourceForge or Saxonica sites. (It is the same file in both cases). Unzip the contents
of this file into the same directory as the Saxon software. When you run a program that
uses Saxon, this program as well as Saxon itself will need to be on the classpath.
For more details of the classpath, see <a class="bodylink" href="../../about/installationjava.xml">Installing (Java)</a>.</p>
         </li>
         <li content="para">
            <p>If you are using features specific to Saxon-PE or Saxon-EE, the commercial editions of Saxon, you will need
to obtain a file containing a licence key. You can apply for a free 30-day license key by going to
<a href="http://www.saxonica.com/" class="bodylink">www.saxonica.com</a> and clicking on "Evaluation Copy". The license
key file will be sent by email within 24 hours. This file, called <code>saxon-license.lic</code>,
  should be placed in the same directory where the file <code>saxon9pe.jar</code> or
  <code>saxon9ee.jar</code> is found. <i>It is no
longer necessary for the directory containing the license file to be on the classpath.</i>
            </p>
         </li>
      </ol>
      <p>You can now run one of the sample stylesheets or queries that comes with in the 
<code>saxon-resources</code> download.
Assuming you installed Saxon-HE into <code>c:\saxon</code>, make this your current directory, and type:</p>
      <p><i>for XSLT (all on one line):</i></p>
      <div class="codeblock"
           style="border: solid thin; background-color: #B1CCC7; padding: 2px">
         <pre>
            <code>java -cp saxon9he.jar net.sf.saxon.Transform -t -s:samples\data\books.xml 
     -xsl:samples\styles\books.xsl -o:c:\temp.html</code>
         </pre>
      </div>
      <p><i>for XQuery (all on one line):</i></p>
      <div class="codeblock"
           style="border: solid thin; background-color: #B1CCC7; padding: 2px">
         <pre>
            <code>java -cp saxon9he.jar net.sf.saxon.Query -t 
   -s:samples\data\books.xml -q:samples\query\books-to-html.xq &gt;c:\temp.html</code>
         </pre>
      </div>
      <p>Now open <code>c:\temp.html</code> in your browser to check that it worked.</p>
      <p>For more details on installing Saxon on the Java platform, see 
<a class="bodylink" href="../../about/installationjava.xml">Installing (Java)</a></p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="gettingstarteddotnet.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>