TransformerFactory ExceptionThe following Runtime exception java.lang.NoClassDefFoundError: org/apache/xalan/processor/TransformerFactoryImpl normally happens when we try to convert an DOM object to XML representation.


The following is an example of on such Exception Stack Trace that is generated.

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xalan/processor/TransformerFactoryImpl
    at weblogic.xml.jaxp.RegistryTransformerFactory.<init>(<!>
    at weblogic.xml.jaxp.RegistrySAXTransformerFactory.<init>(
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at javax.xml.transform.FactoryFinder.newInstance(Unknown Source)
    at javax.xml.transform.FactoryFinder.findJarServiceProvider(Unknown Source)
    at javax.xml.transform.FactoryFinder.find(Unknown Source)
    at javax.xml.transform.TransformerFactory.newInstance(Unknown Source)
    at com.livrona.snippets.util.DomXmlExample.<init>(
    at com.livrona.snippets.util.DomXmlExample.main(
Caused by: java.lang.ClassNotFoundException: org.apache.xalan.processor.TransformerFactoryImpl
    at$ Source)
    at Method)
    at Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 14 more


Basically in this case the TransformerFactory is created to transform the DOM to XML. The factory tries to find the implementation of the Transformer ( org/apache/xalan/processor/TransformerFactoryImpl) at Runtime but cannot find that class in the ClassPath and throws the exception instead.


So the simple fix for this issue to add xlan.jar into the classpath and try again. The version of this jar file you use would depend on your JDK version or version of other XML related libraries used to ensure compatibility.

Xalan-Java is an XSLT processor for transforming XML documents into HTML, text, or other XML document types. It implements XSL Transformations (XSLT) Version 1.0 and XML Path Language (XPath) Version 1.0 and can be used from the command line, in an applet or a servlet, or as a module in other program. It can be downloaded from

Code Used

The following is the sample code that can cause such an exception to happen if xlan.jar is not in the classpath.

// Output the XML
// set up a transformer
TransformerFactory transfac = TransformerFactory.newInstance();
Transformer trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
trans.setOutputProperty(OutputKeys.INDENT, "yes");

// create string from xml tree
StringWriter sw = new StringWriter();
// set the String Writer to StreamResult
StreamResult result = new StreamResult(sw);

// create dom source from dom document

DOMSource source = new DOMSource(doc);
// transform dom source into Stream Result
trans.transform(source, result);
String xmlString = sw.toString();
// print xml
System.out.println("XML:n" + xmlString);