蜡染传递库依赖

时间:2015-05-27 13:00:13

标签: java gradle

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

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

摇篮:

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

由于

1 个答案:

答案 0 :(得分:1)

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

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

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

因此推到maven时罐子没有正确构建。

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

干杯