You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Roger L. Costello" <co...@mitre.org> on 2002/06/28 14:09:59 UTC

Invoking XALAN from a Servlet running on Tomcat 4.0.3

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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Invoking XALAN from a Servlet running on Tomcat 4.0.3

Posted by Jacob Kjome <ho...@visi.com>.
Hello Roger,

Assuming you are using j2sdk1.4.x, put your version of Xalan (might as
well be the latest) in JAVA_HOME/jre/lib/endorsed

This will guarantee that your version of Xalan will be used.  It will
even override jars that you put in TOMCAT_HOME/lib or
TOMCAT_HOME/common/lib.

You can do a similar thing if you use Tomcat 4.1.x.  You can just put
your Xalan jar in the TOMCAT_HOME/common/endorsed directory.

Jake

Friday, June 28, 2002, 7:09:59 AM, you wrote:

RLC> Hi Folks,

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

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

RLC>    Transformer transformer = tFactory.newTransformer(xsl_ss);

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

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

RLC> Some things to note:

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

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

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

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

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

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

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

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


RLC> --
RLC> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
RLC> For additional commands, e-mail: <ma...@jakarta.apache.org>



-- 
Best regards,
 Jacob                            mailto:hoju@visi.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>