NoSuchMethodException:org.apache.fop.apps.FopFactory.newInstance()

NoSuchMethodException: org.apache.fop.apps.FopFactory.newInstance()

此代码:

WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(is);
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setWmlPackage(wordMLPackage);
Docx4J.toFO(foSettings, baos, Docx4J.FLAG_EXPORT_PREFER_XSL);
//Docx4J.toPDF(wordMLPackage, baos);

引发此错误:

java.lang.NoSuchMethodException: org.apache.fop.apps.FopFactory.newInstance() at java.lang.Class.getDeclaredMethod(Class.java:2130) at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.createFopFactory(FORendererApacheFOP.java:335) at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.getFopFactory(FORendererApacheFOP.java:253) at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.render(FORendererApacheFOP.java:119) at org.docx4j.convert.out.fo.AbstractFOExporter.postprocess(AbstractFOExporter.java:168) at org.docx4j.convert.out.fo.AbstractFOExporter.postprocess(AbstractFOExporter.java:47) at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:82) at org.docx4j.Docx4J.toFO(Docx4J.java:575)

Maven

<dependency>
    <groupId>org.docx4j</groupId>
    <artifactId>docx4j</artifactId>
    <version>3.3.6</version>
</dependency>
<dependency>
    <groupId>org.docx4j</groupId>
    <artifactId>docx4j-export-fo</artifactId>
    <version>3.3.6</version>
</dependency>

这里可能有什么问题?

乍一看,确认 FOP 2.2 在您的路径上。

但是从堆栈跟踪来看,它看起来不像 export-fo v3.3.6,因此请检查您的 class 路径以确保您没有更早的 export-fo。