I wrote some code years ago that uses Castor to marshall a java object tree
to XML in preparation for transforming that document to PDF using Apache
FOP. I am in the process of moving the application to the latest version of
JBoss (version 7.1.1) where it had been running in 4.2.2. I have posted this
issue on JBoss boards, but so far have gotten no response, so I thought I'd
ask here. At the same time that I'm migrating the code, I'm moving from Ant
to Maven to produce an ear which contains the war that houses the code that
tries to do the transformation.
At runtime, executing the following code:
public void asPdfDocument(Fop fop) throws Exception {
// Serialize the report to an in-memory xml representation
// using Castor then Transform that document to an fo document
// using XLST and finally, produce a pdf document from the
// fo document using fop.
// Use setParameter(name, value) on the transformer before
// using it to set the print date.
InputStream is = null;
is = this.getClass().getResourceAsStream(
"/xml/MatchReportMapping.xml");
if (is == null) {
throw new Exception("Failed getting xml mapping.");
}
InputSource map = new InputSource(is);
// Instantiate the Castor Mapping and get
// it to load the map file
Mapping xmlMapping = new Mapping(getClass().getClassLoader());
xmlMapping.loadMapping(map);
// Create the marshaller that will generate the
// xml document giving it an in-memory character array
// for its results
CharArrayWriter xmlDoc = new CharArrayWriter();
Marshaller marshaller = new Marshaller(xmlDoc);
// Give the marshaller the mapping so that it can
// produce proper xml
marshaller.setMapping(xmlMapping);
// And generate the xml
marshaller.marshal(this);
log.debug(xmlDoc.toString());
// xsl tells Xalan how to transform the xml
// to xml-fo
is = this.getClass().getResourceAsStream("/xml/MatchReport.xsl");
if (is == null) {
throw new Exception("Failed getting stylesheet.");
}
StreamSource xsl = new StreamSource(is);
// Create an xsl transformer based on the xsl
// file we just loaded
Transformer xslt = TransformerFactory.newInstance().newTransformer(xsl);
xslt.setParameter("title", title);
xslt.setParameter("print-date", DateFormat.getDateInstance(
DateFormat.SHORT).format(new Date()));
xslt.transform(
new StreamSource(new CharArrayReader(xmlDoc.toCharArray())),
new SAXResult(fop.getDefaultHandler()));
}
Produces the following exception (on the line that attempts to instantiate a
new Marshaller):
java.lang.RuntimeException: Could not instantiate serializer
com.sun.org.apache.xml.internal.serialize.XMLSerializer:
java.lang.ClassNotFoundException:
com.sun.org.apache.xml.internal.serialize.XMLSerializer from [Module
"deployment.myEar.ear.myAdmin.war:main" from Service Module Loader]
This is the content of the war's lib directory:
antlr-2.7.7.jar castor-xml-1.3.2.jar
avalon-framework-api-4.3.1.jar commons-beanutils-1.8.3.jar
avalon-framework-impl-4.3.1.jar commons-collections-20040616.jar
batik-anim-1.7.jar commons-digester-1.6.jar
batik-awt-util-1.7.jar commons-fileupload-1.0.jar
batik-bridge-1.7.jar commons-io-1.3.1.jar
batik-css-1.7.jar commons-lang-2.1.jar
batik-dom-1.7.jar commons-logging-1.1.1.jar
batik-ext-1.7.jar commons-validator-1.1.4.jar
batik-extension-1.7.jar fop-1.1.jar
batik-gvt-1.7.jar json-20090211.jar
batik-js-1.7.jar oro-2.0.7.jar
batik-parser-1.7.jar stax-1.2.0.jar
batik-script-1.7.jar stax-api-1.0.1.jar
batik-svg-dom-1.7.jar struts-1.2.9.jar
batik-svggen-1.7.jar xalan-2.5.1.jar
batik-transcoder-1.7.jar xml-apis-1.0.b2.jar
batik-util-1.7.jar xml-apis-ext-1.3.04.jar
batik-xml-1.7.jar xmlgraphics-commons-1.5.jar
castor-core-1.3.2.jar
(I have tried adding xercesImpl 2.11.0 to no effect.)
A search for the declaration of the class that can't be found at runtime (in
Eclipse) finds it in classes.jar in
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes.
It's not at all clear to me how, if the class is declared in the Java
Runtime, it cannot be found.
Can anyone help me figure out what the problem might be?
Thanks in advance.
Richard
--
View this message in context:
http://old.nabble.com/Marshaller-can%27t-find-XMLSerializer-tp35806976p35806976.html
Sent from the Castor - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email