5

I cannot seem to find it and Netbeans says that the package does not exist? Which jar do I have to get to have package org.w3c.dom.svg? I'm using batik SVG

Bashir Beikzadeh
  • 761
  • 8
  • 15

5 Answers5

4

The W3C reference link in Jelle Fresen's answer is v.1.1 of the spec, from 2010. Unfortunately Batik 1.9 (the latest as of this writing) is written against the much older 1.0 spec, from 2001.

There are surely other incompatibilities between the 1.0 and 1.1 specs, but the first one I encountered was a java.lang.NoSuchMethodError: org.w3c.dom.svg.SVGTransformList.getNumberOfItems()I because Apache expects ints, whereas SVG 1.1 API speaks in long values.

The W3C's SVG 1.0 reference implementation can be found here, at least for now: https://www.w3.org/TR/SVG10/java.html

Unfortunately that package has a dependency on SMIL; 3.0 is the newest version that predates SVG 1.1, and only contains two Java classes, which you can find here: https://www.w3.org/TR/SMIL3/smil-timing.html#q142

You can simply build your own JAR from that code. Or you can probably just use Maven to resolve all your problems. Unfortunately, the client I'm working with still lives in dependency hell and these things need to be resolved manually.

Many thanks to Jelle Fresen, whose link led me to what I was looking for.

Update: OK, it looks like the Batik distribution contains these libraries too, unsurprisingly. You can download it here, as I already had: https://xmlgraphics.apache.org/batik/download.html

Confusingly, batik-all-1.9.jar (included in batik-bin-1.9.zip) doesn't contain everything you need.

So the real (most practical, if you're not blessed by Maven) answer to the original question is that the package org.w3c.dom.svg can be found in xml-apis-ext-1.3.04.jar, provided with the Batik distribution.

Lambart
  • 1,985
  • 2
  • 21
  • 37
3

I know that this question is probably very old but Ive been recently having the same problem (when working with batik and this dependency was missing on the portal)...

I solved it by downloading w3c.jar from this site. Hope it helps someone in the future!

Smajl
  • 7,555
  • 29
  • 108
  • 179
  • 2
    Useful... if you trust random sites on the internet. I'd rather get the source _from_ the source: https://www.w3.org/TR/SVG10/java.html – Lambart Jan 22 '18 at 18:16
2

What you are looking for is the Java Language Binding of the SVG specification and can be found in Appendix D.1 of W3C's SVG Recommendation: http://www.w3.org/TR/SVG11/java.html

Jelle Fresen
  • 1,916
  • 1
  • 20
  • 24
  • 1
    Unfortunately that link leads to SVG 1.1, and Batik 1.9 appears to depend on SVG 1.0. You'll get errors such as `java.lang.NoSuchMethodError: org.w3c.dom.svg.SVGTransformList.getNumberOfItems()I` because Apache expects `int`s where SVG 1.1 API speaks in `long`s. But I found the SVG 1.0 reference spec here: https://www.w3.org/TR/SVG10/java.html – Lambart Jan 22 '18 at 18:15
1

I had a similar need, so that I could pass SVG and MathML documents between independent modules. To my knowledge, there is no official blessed Maven-hosted jar file for these, but I did make a very unofficial jar file of the official published bindings and put them up on Maven back in 2007. The MathML bindings had some minor compile errors that I corrected before building. The SMIL dependency is also provided transitively. Here are the Maven dependency descriptors:

<!-- The SVG DOM bindings for Java, written by the W3C, distributed by aXSL. -->
<dependency>
    <groupId>org.axsl.org.w3c.dom.svg</groupId>
    <artifactId>svg-dom-java</artifactId>
    <version>1.1</version>
</dependency>


<!-- The MathML DOM bindings for Java, written by the W3C, distributed by aXSL. -->
<dependency>
    <groupId>org.axsl.org.w3c.dom.mathml</groupId>
    <artifactId>mathml-dom-java</artifactId>
    <version>2.0</version>
</dependency>
0

I struck this problem trying to build the Batik Swing example at https://xmlgraphics.apache.org/batik/using/swing.html with IntelliJ.

For me, the solution came (not immediately, believe me) by getting the Maven libraries: xml-apis:xml-apis:2.0.2 and... xml-apis:xml-apis-ext:1.3.04

(Those were the latest versions available to me at the time of this writing)

[Update] The above dependencies were only necessary when using the batik: Maven batik repository. I eventually got the code working by getting all of the libraries (for version 1.7) in batik:*:1.7. However, there is a problem with SVG masks with those libraries. I discovered that it is far better to use org.apache.xmlgraphics:batik-all. That fixes the svg:mask problem and negates the need for other dependencies, including the xml-apis: ones above.