gpt4 book ai didi

java - Batik 传递库依赖项

转载 作者:搜寻专家 更新时间:2023-10-31 20:33:37 26 4
gpt4 key购买 nike

我正在使用 Gradle 获取 Batik(一个 SVG 库)并且开箱即用,它缺少一些可传递的库。我应该放哪一个?

我已经尝试获取 xml-api 或 Xerces 库

Gradle :

version = 1.0
mainClassName = 'com.foilen.svgexporter.SvgExporter'

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

dependencies {
compile 'args4j:args4j:2.32'
compile 'org.apache.xmlgraphics:batik-rasterizer:1.8'
}

Java代码:

PNGTranscoder transcoder = new PNGTranscoder();
InputStream in = new FileInputStream("character_man_black.svg");
TranscoderInput input = new TranscoderInput(in);
OutputStream ostream = new FileOutputStream("character_man_black.png");
TranscoderOutput output = new TranscoderOutput(ostream);
transcoder.transcode(input, output);

// Flush and close the output.
ostream.flush();
ostream.close();
in.close();

执行错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:455)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.apache.batik.anim.dom.SVGDOMImplementation.createDocument(Unknown Source)
at org.apache.batik.dom.util.SAXDocumentFactory.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:379)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:605)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3138)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:880)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
at org.apache.batik.dom.util.SAXDocumentFactory.createDocument(Unknown Source)
at org.apache.batik.dom.util.SAXDocumentFactory.createDocument(Unknown Source)
at org.apache.batik.anim.dom.SAXSVGDocumentFactory.createDocument(Unknown Source)
at org.apache.batik.anim.dom.SAXSVGDocumentFactory.createDocument(Unknown Source)
at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown Source)
at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
at com.foilen.svgexporter.SvgExporter.main(SvgExporter.java:66)
Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 34 more

谢谢

最佳答案

我下载了batik-1.8的源码,缺少的类是官方源码的一部分。

我用 ant maven-artifacts 编译了这些库,并检查了所有的 jar 文件,看看哪个得到了 org.w3c.dom 包。我在 batik-ext-1.8 中找到了它。

Gradle 正在下载这个 jar,但是那里只有一个 Manifest 目录;不是类。参见 http://central.maven.org/maven2/org/apache/xmlgraphics/batik-ext/1.8/batik-ext-1.8.jar

所以当推送到 maven 时,jar 没有正确构建。

我在这里打开了一个错误报告:https://issues.apache.org/jira/browse/BATIK-1120

干杯

关于java - Batik 传递库依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30483255/

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