gpt4 book ai didi

java - 找不到类 FOP

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:59:35 26 4
gpt4 key购买 nike

你好,我正在尝试使用 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)

我在构建路径中有 FOP 库以及 xmlgraphicscommons loggingAvalon 框架

这是我要运行的代码

        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 属于 xmlgraphics-commons-1.5.jar。只需将 xmlgraphics-commons-1.5.jar 添加到您的类路径中,即可解决问题。

关于java - 找不到类 FOP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12801477/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com