gpt4 book ai didi

Java batik : ClassNotFoundException: org. apache.batik.dom.svg.SVGDOMImplementation

转载 作者:行者123 更新时间:2023-12-02 04:59:09 28 4
gpt4 key购买 nike

我有一个 servlet,我试图用包含 svg 代码的字符串创建 pdf。因此我有这个代码:

public class Conversion extends HttpServlet {

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String svgString = req.getParameter("svg");
StringReader svg = new StringReader(svgString);
File pdf = new File("/tmp/chart.pdf");

Transcoder transcoder = new PDFTranscoder();
TranscoderInput transcoderInput = new TranscoderInput(svg);
TranscoderOutput transcoderOutput = new TranscoderOutput(new FileOutputStream(pdf));

try {
transcoder.transcode(transcoderInput, transcoderOutput);
} catch (TranscoderException e) {
e.printStackTrace();
}

resp.setContentType("application/pdf");
InputStream in = new FileInputStream(pdf);
ServletOutputStream out = resp.getOutputStream();

byte[] buffer = new byte[4096];
while(in.read(buffer, 0, 4096) != -1){
out.write(buffer, 0, 4096);
}
in.close();
out.flush();
out.close();
}
}

执行时出现此错误:

java.lang.ClassNotFoundException: org.apache.batik.dom.svg.SVGDOMImplementation
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1166)
at org.apache.fop.svg.AbstractFOPTranscoder.<init>(AbstractFOPTranscoder.java:107)
at org.apache.fop.svg.PDFTranscoder.<init>(PDFTranscoder.java:84)
at com.Webmap_read.Conversion.doGet(Conversion.java:38)
at com.Webmap_read.Conversion.doPost(Conversion.java:68)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1526)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1482)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

当我检查构建路径时,Batik 1.8 存档文件中包含的所有 JAR 似乎都是从以下位置下载的:http://apache.lauf-forum.at/xmlgraphics/batik/binaries/ 。但类(class)SVGDOMImplementation不在这里。我如何导入所有必要的 JAR/类以及为什么它们不包含在标准 zip 中?它现在让我发疯...或者是否有更简单的方法将 SVG 转换为 PDF?

最佳答案

看看http://www.findjar.com/class/org/apache/batik/dom/svg/SVGDOMImplementation.html检查列出的 jar 是否在应用程序类路径中。

我建议您从https://xmlgraphics.apache.org/batik/download.html下载 batik (官方网站)

关于Java batik : ClassNotFoundException: org. apache.batik.dom.svg.SVGDOMImplementation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34178503/

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