java 未找到类 FOP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12801477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
class not found FOP
提问by user1731812
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
嗨,我正在尝试使用 FOP 将 xml 文件转换为 pdf,但我一直遇到错误,现在我遇到了错误
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 FOPlibrary in the build path as well as xmlgraphicsand commons loggingand Avalon framework
我在构建路径中有FOP库以及xmlgraphics和commons 日志记录和Avalon 框架
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();
}
}
}
回答by Mrinal
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.jarin your classpath, it will resolve the issue.
org.apache.xmlgraphics.util.MimeConstants
属于xmlgraphics-commons-1.5.jar。只需在您的类路径中包含xmlgraphics-commons-1.5.jar,它就会解决问题。
回答by Johny
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:
真的很老的线程,但我花了很长时间来解决这个问题,所以对于从 FOP 1.1 到 2.0 的迁移,在 pom 中进行了这样的更改:
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>
回答by Joey Ezekiel
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
我想你已经找到了这个 - 但无论如何对于那些没有的人:FOP 1.1 的主干确实有 FopConfParser 它引用了 xmlgraphics.io.ResourceResolver
and the trunk of xmlgraphics commons does have the ResourceResolver:
并且 xmlgraphics commons 的主干确实有 ResourceResolver:
So as a solution, update to trunk! Happy coding :)
因此,作为解决方案,更新到主干!快乐编码:)
回答by Mill3r
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.
从 0.92b 更新到 FOP 1.1 时,我遇到了类似的问题,但没有找到 MimeConstants 类。
I resolved it by using the xmlgraphics-commons version in the source distribution of FOP version that I was using.
我通过在我使用的 FOP 版本的源代码分发中使用 xmlgraphics-commons 版本解决了这个问题。
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.
尝试使用构建 FOP 版本时使用的 xmlgraphics-commons jar,它可以在 FOP 源代码分发的 lib 文件夹中找到。
回答by Nicola Musatti
I could not find an xmlgraphics
jar, but I did find xmlgraphics-commons. Is that what you meant?
我找不到xmlgraphics
jar,但我确实找到了xmlgraphics-commons。这是你的意思吗?
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?
从我上面链接的页面看来,它似乎不包含org.apache.xmlgraphics.io
包,但它确实包含org.apache.xmlgraphics.util.io
. 也许你的意思是那个?