Hi so i am trying to use FOP to turn an xml file into pdf and i keep on running into errors, right now i have the error
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlgraphics/io/ResourceResolver
at org.apache.fop.apps.FopConfParser.<init>(FopConfParser.java:122)
at org.apache.fop.apps.FopFactory.newInstance(FopFactory.java:132)
at run.ExampleFO2PDF.main(ExampleFO2PDF.java:62)
i have the FOP library in the build path as well as xmlgraphics and commons logging and Avalon framework
This is the code i am trying to run
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.fop.apps.*;
import org.xml.sax.SAXException;
public class pdf{
public static void main(String[] args) throws SAXException, IOException, TransformerException
{
FopFactory fopFactory = FopFactory.newInstance(new File("."));
OutputStream out = new BufferedOutputStream(new FileOutputStream(new File("D:/temp/myfile.pdf")));
try {
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(); // identity transformer
Source src = new StreamSource(new File("D:/temp/test.xml"));
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
} finally {
//Clean-up
out.close();
}
}
}
abstract interface org.apache.fop.apps.MimeConstants implements org.apache.xmlgraphics.util.MimeConstants
org.apache.xmlgraphics.util.MimeConstants
belong to xmlgraphics-commons-1.5.jar. Just include xmlgraphics-commons-1.5.jar in your classpath, it will resolve the issue.
I guess you've figured out this one - but anyway for those that haven't: The trunk of FOP 1.1 does have the FopConfParser which references the xmlgraphics.io.ResourceResolver
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopConfParser.java?view=markup
and the trunk of xmlgraphics commons does have the ResourceResolver:
http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/io/ResourceResolver.java?view=log
So as a solution, update to trunk! Happy coding :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With