tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Roger L. Costello" <>
Subject Invoking XALAN from a Servlet running on Tomcat 4.0.3
Date Fri, 28 Jun 2002 12:09:59 GMT
Hi Folks,

At the bottom of this message is Java code to invoke the XSLT Processor,
XALAN, with two in-memory strings, representing the XML and Stylesheet
respectively.  I know that this code works.  I have a program which
invokes this method and it works great.

However, when I use this code within a Java servlet that is running on
Tomcat 4.0.3 it fails .  Tomcat blows up on this statement:

   Transformer transformer = tFactory.newTransformer(xsl_ss);

Here is the first line of the exception that Tomcat raises:

    java.lang.NoClassDefFoundError: javax/xml/transform/Source

Some things to note:

1. The exception says that Tomcat can't find
javax.xml.transform.Source.class. The package javax.xml.transform is in
xml-apis.jar.  I have this jar file in my webapps WEB-INF/lib folder.

2. The package javax.xml.transform contains TransformerFactory.class
(which Tomcat found), as well as Source.class (which Tomcat says that it
can't find).

I don't understand how Tomcat can find one class but not the other, when
they are both in the same jar file. 

Can someone explain what is going on here?  Has anyone successfully
invoked XALAN from a Java servlet running on Tomcat?  /Roger

    // This code shows how to invoke xalan by passing to it the 
    // xml and xsl as in-memory strings

    public static String doTransform(String xml, String xsl)
    throws TransformerException, TransformerConfigurationException, 
           FileNotFoundException, IOException {

        TransformerFactory tFactory = TransformerFactory.newInstance();
        StringReader xsl_sr = new StringReader(xsl);
        StreamSource xsl_ss = new StreamSource(xsl_sr);
        ** the following statement is where it fails **
        Transformer transformer = tFactory.newTransformer(xsl_ss);

        StringReader xml_sr = new StringReader(xml);
        StreamSource xml_ss = new StreamSource(xml_sr);
        StringWriter out_sw = new StringWriter();
        StreamResult out_sr = new StreamResult(out_sw);
        transformer.transform(xml_ss, out_sr);
        return out_sw.toString();

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message