Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batik transitive libraries dependencies

Tags:

java

gradle

I am using Gradle to get Batik (an SVG library) and out of the box, it is missing some transitive libraries. Which one should I put?

I already tried to get the xml-api or Xerces lib

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 code:

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();

Execution error:

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

Thanks

like image 458
Simon Levesque Avatar asked Nov 09 '22 12:11

Simon Levesque


1 Answers

I downloaded the source code of batik-1.8 and the missing class is part of the official source code.

I compiled the libraries with ant maven-artifacts and checked all the jar files to see which one got that org.w3c.dom package. I found it in batik-ext-1.8.

This jar is being downloaded by Gradle, but there is only a Manifest directory there; not classes. See http://central.maven.org/maven2/org/apache/xmlgraphics/batik-ext/1.8/batik-ext-1.8.jar

So the jar was not correctly built when pushed to maven.

I opened a bug report here: https://issues.apache.org/jira/browse/BATIK-1120

Cheers

like image 177
Simon Levesque Avatar answered Nov 15 '22 13:11

Simon Levesque