7

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();
                }
           }

    }
user1731812
  • 71
  • 1
  • 1
  • 4
  • 1
    Please show us how you're *running* the code. It looks like you haven't got xmlgraphics in the classpath. – Jon Skeet Oct 09 '12 at 13:44

5 Answers5

5
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.

Matthias
  • 3,582
  • 2
  • 30
  • 41
Mrinal
  • 464
  • 5
  • 3
  • According to the question, the missing class is `org/apache/xmlgraphics/io/ResourceResolver`. This is _not_ contained in `xmlgraphics-commons-1.5.jar`, so including this jar will _not_ fix OP's problem. – Dawood ibn Kareem Oct 05 '16 at 07:58
2

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 :)

Joey Ezekiel
  • 1,017
  • 1
  • 11
  • 26
2

Really old thread, but i takes me so long to resolve this, so for migration from FOP 1.1 to 2.0 made this change in pom like this:

from:

<dependency>
    <groupId>org.apache.xmlgraphics</groupId> 
    <artifactId>fop</artifactId> 
    <version>1.1</version>
</dependency>

to:

        <dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>fop</artifactId>
            <version>2.0</version>
            <exclusions>
                <exclusion>                  
                    <groupId>org.apache.xmlgraphics</groupId>
                    <artifactId>xmlgraphics-commons</artifactId>
                </exclusion>  
                <exclusion>
                    <groupId>org.apache.xmlgraphics</groupId>
                    <artifactId>batik-svg-dom</artifactId>
                </exclusion>  
                <exclusion>
                    <groupId>org.apache.xmlgraphics</groupId>
                    <artifactId>batik-bridge</artifactId>
                </exclusion>  
                <exclusion>
                    <groupId>org.apache.xmlgraphics</groupId>
                    <artifactId>batik-awt-util</artifactId>
                </exclusion>  
                <exclusion>
                    <groupId>org.apache.xmlgraphics</groupId>
                    <artifactId>batik-gvt</artifactId>
                </exclusion>  
                <exclusion>
                    <groupId>org.apache.xmlgraphics</groupId>
                    <artifactId>batik-transcoder</artifactId>
                </exclusion>  
                <exclusion>
                    <groupId>org.apache.xmlgraphics</groupId>
                    <artifactId>batik-extension</artifactId>
                </exclusion>  
                <exclusion>
                    <groupId>org.apache.xmlgraphics</groupId>
                    <artifactId>batik-ext</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>xmlgraphics-commons</artifactId>
            <version>2.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>batik-svg-dom</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>batik-bridge</artifactId>
            <version>1.8</version>
        </dependency>    
        <dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>batik-awt-util</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>batik-gvt</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>batik-transcoder</artifactId>
            <version>1.8</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.xmlgraphics</groupId>
                    <artifactId>fop</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>batik-extension</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>batik-ext</artifactId>
            <version>1.8</version>
        </dependency>
Johny
  • 93
  • 1
  • 6
  • 1
    Can you describe what you changed? A change involves a movement from one point to another. I only see the result of your change. It would be nice to see a delta. – Edgar Klerks Jun 18 '15 at 11:34
  • Sorry, i thought that its obvious, `org.apache.xmlgraphics fop 1.1` – Johny Jun 23 '15 at 11:48
  • To finish this topic, i also changed fopFactory creation - from: `FopFactory fopFactory = FopFactory.newInstance(); fopFactory.setStrictValidation(false); fopFactory.getFontManager();` to `FopFactoryBuilder builder = new FopFactoryBuilder(new File(".").toURI()); builder.setStrictFOValidation(false); FopFactory fopFactory = builder.build();` – Johny Jun 23 '15 at 11:55
1

Old thread, adding a bit more for completeness.

I ran in to a similar problem when updating to FOP 1.1 from 0.92b with the MimeConstants class not being found.

I resolved it by using the xmlgraphics-commons version in the source distribution of FOP version that I was using.

Try using the xmlgraphics-commons jar that was used when your version of FOP was built, which can be found in the lib folder in the FOP source distribution.

Mill3r
  • 78
  • 1
  • 8
0

I could not find an xmlgraphics jar, but I did find xmlgraphics-commons. Is that what you meant?

From the page I linked above it would seem that it doesn't contain a org.apache.xmlgraphics.io package, but it does contain org.apache.xmlgraphics.util.io. Maybe you meant that one?

Nicola Musatti
  • 17,834
  • 2
  • 46
  • 55