gpt4 book ai didi

xsl-fo - FOP batik NoClassDefFoundError : org/apache/batik/bridge/UserAgent

转载 作者:行者123 更新时间:2023-12-03 23:55:58 24 4
gpt4 key购买 nike

我不使用 maven、pom 或任何东西。我只有简单的测试类进行测试,我只是尝试将 XSL-FO 转换为 PDF,但出现此错误。
代码很简单:

package testing;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.sax.SAXResult;

import javax.xml.transform.Result;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;

import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;

import org.apache.xmlgraphics.util.MimeConstants;


public class test {

public static void main(String[] args) {
String pth="C:/Temp/";
FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());
TransformerFactory factory = TransformerFactory.newInstance();
OutputStream out;
try
{
out = new BufferedOutputStream(new FileOutputStream(new File(pth+"myfile.pdf")));

InputStream in = new FileInputStream(pth+"everything.fo");

Source source = null;
Transformer transformer = factory.newTransformer();
source = new StreamSource(in);
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(source, res);
} catch (Exception e)
{
e.printStackTrace();;
}
}
}

这是结果:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/batik/bridge/UserAgent
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.getDeclaredConstructor(Class.java:2178)
at org.apache.xmlgraphics.util.Service.providers(Service.java:85)
at org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry.discoverClasspathImplementations(ImageImplRegistry.java:115)
at org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry.<init>(ImageImplRegistry.java:79)
at org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry.<init>(ImageImplRegistry.java:87)
at org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry.<clinit>(ImageImplRegistry.java:71)
at org.apache.xmlgraphics.image.loader.ImageManager.<init>(ImageManager.java:64)
at org.apache.fop.apps.FopFactoryBuilder$FopFactoryConfigImpl.<init>(FopFactoryBuilder.java:381)
at org.apache.fop.apps.FopFactoryBuilder.<init>(FopFactoryBuilder.java:90)
at org.apache.fop.apps.FopFactoryBuilder.<init>(FopFactoryBuilder.java:81)
at org.apache.fop.apps.FopFactoryBuilder.<init>(FopFactoryBuilder.java:71)
at org.apache.fop.apps.FopFactory.newInstance(FopFactory.java:143)
at testing.test5.main(test5.java:37)
Caused by: java.lang.ClassNotFoundException: org.apache.batik.bridge.UserAgent
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 16 more

这是我的库:
My Libs

我做错了什么?
正如我所说,我不使用 POM、MAVEN 等,只是用于测试目的的简单 java 代码。我知道有一些依赖关系,但没有 POM 我如何管理这些东西?

这是我的 FO 文件:
everything.fo

最佳答案

关于这个问题,我使用最新版本的 batik 解决了我的问题。

在 POM.xml 我有这个:

<dependency> 
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-bridge</artifactId>
<version>1.11</version>
</dependency>

关于xsl-fo - FOP batik NoClassDefFoundError : org/apache/batik/bridge/UserAgent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47309752/

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