Page 1 of 1

Xalan dependencies

PostPosted: Tue Jan 18, 2011 7:36 pm
by Franke
When reading a normal docx with just a few paragraphs, tables, header + footer and two images, I get an error:
Code: Select all
ERROR: XmlUtils: javax.xml.transform.TransformerFactoryConfigurationError: Provider org.apache.xalan.processor.TransformerFactoryImpl not found (XmlUtils.java, line 131)


However, the file parses fine, but what is this dependency about? If I do add xalan-2.7.1.jar I can read the file without errors occuring, but the save method throws a no class found exception:

Code: Select all
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xml/serializer/TreeWalker
        at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:823)
        at org.docx4j.model.datastorage.CustomXmlDataStorageImpl.writeDocument(CustomXmlDataStorageImpl.java:84)
        at org.docx4j.openpackaging.io.SaveToZipFile.saveRawXmlPart(SaveToZipFile.java:212)
        at org.docx4j.openpackaging.io.SaveToZipFile.saveRawXmlPart(SaveToZipFile.java:188)
        at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:362)
        at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:325)
        at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:377)
        at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:325)
        at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:158)
        at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:99)
        at org.docx4j.openpackaging.packages.WordprocessingMLPackage.save(WordprocessingMLPackage.java:204)
        at javaapplication1.Docxtest.export(Docxtest.java:223)
        at javaapplication1.Docxtest.main(Docxtest.java:193)
Caused by: java.lang.ClassNotFoundException: org.apache.xml.serializer.TreeWalker
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        ... 13 more


So it seems that docx4j has additional dependencies compared to the getting started, AND the lib itself that comes with is corrupt? Thoughts on this? It really works fine just ignoring the library, but I dislike getting random errors.

Re: Xalan dependencies

PostPosted: Tue Jan 18, 2011 7:57 pm
by jason
Franke wrote:When reading a normal docx with just a few paragraphs, tables, header + footer and two images, I get an error:
Code: Select all
ERROR: XmlUtils: javax.xml.transform.TransformerFactoryConfigurationError: Provider org.apache.xalan.processor.TransformerFactoryImpl not found (XmlUtils.java, line 131)



See the static initializer in XmlUtils. If anything in that class is used, the static init is of course executed, and it is that that configures the transformer.

Franke wrote:
Code: Select all
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xml/serializer/TreeWalker
        at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:823)
        at org.docx4j.model.datastorage.CustomXmlDataStorageImpl.writeDocument(CustomXmlDataStorageImpl.java:84)



Code: Select all
mvn dependency:tree
:
[INFO] +- xalan:xalan:jar:2.7.1:compile
[INFO] |  \- xalan:serializer:jar:2.7.1:compile
[INFO] |     \- xml-apis:xml-apis:jar:1.3.04:compile


I'll update the Getting Started guide so that where it refers to Xalan, it refers to Xalan and its dependencies. You can get the dependencies from the docx4j download dir, from the Xalan distribution, or via maven.

Re: Xalan dependencies

PostPosted: Tue Jan 18, 2011 8:49 pm
by Franke
Ah thank you, it works better now. On a related matter, when exporting to PDF, it seems to require batik-util.jar from Apache, this might also be good to put on the getting started page.