Class not found FOP

Hi, so I am trying to use FOP to turn an xml file into a pdf, and I continue to work with errors, right now I have an 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 a FOP library in the build path, as well as registering xmlgraphics and commons and the Avalon platform

This is the code I'm 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(); } } } 
+6
source share
5 answers
 abstract interface org.apache.fop.apps.MimeConstants implements org.apache.xmlgraphics.util.MimeConstants 

org.apache.xmlgraphics.util.MimeConstants refer to xmlgraphics-commons-1.5.jar . Just include xmlgraphics-commons-1.5.jar in your classpath, it will fix the problem.

+3
source

I think you understand this, but in any case for those who do not: In the FOP 1.1 tube there is FopConfParser, which refers to xmlgraphics.io.ResourceResolver

http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopConfParser.java?view=markup

and the xmlgraphics commons chest has a ResourceResolver:

http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/io/ResourceResolver.java?view=log

So, as a solution, upgrade your trunk! Happy coding :)

+2
source

Old thread, adding a little more for completeness.

I ran into a similar problem when upgrading to FOP 1.1 from 0.92b with the MimeConstants class not found.

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

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

+1
source

Really old thread, but I have been doing this for so long, so for the transition from FOP 1.1 to 2.0, this change in pom was as follows:

from

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

so that:

  <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> 
+1
source

I could not find a jar of xmlgraphics , but I found xmlgraphics-commons . Is that what you meant?

On the page linked above, it would seem that it does not contain the org.apache.xmlgraphics.io package, but contains org.apache.xmlgraphics.util.io . Did you mean this?

0
source

Source: https://habr.com/ru/post/927261/


All Articles