css4j / echosvg

SVG implementation in the Java™ Language, fork of Apache Batik, supporting level 4 selectors and colors.
Apache License 2.0
39 stars 2 forks source link

XMLReader #89

Closed Frank-99 closed 10 months ago

Frank-99 commented 10 months ago

Hi, I'm getting lost here...

This line of code

private static final SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory();

Throws this Exception:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: io/sf/carte/doc/style/css/nsac/Parser
    at io.sf.carte.echosvg.anim.dom.SAXSVGDocumentFactory.<init>(SAXSVGDocumentFactory.java:79)
    at io.sf.carte.echosvg.anim.dom.SAXSVGDocumentFactory.<init>(SAXSVGDocumentFactory.java:68)

I tried setting it to null also, as suggested here but no luck. Do I need to make my own XMLReader? how can I go about doing so? Or am I just missing something else?

carlosame commented 10 months ago

Throws this Exception:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: io/sf/carte/doc/style/css/nsac/Parser
  at io.sf.carte.echosvg.anim.dom.SAXSVGDocumentFactory.<init>(SAXSVGDocumentFactory.java:79)
  at io.sf.carte.echosvg.anim.dom.SAXSVGDocumentFactory.<init>(SAXSVGDocumentFactory.java:68)

This means that CSS4J is not in your classpath. What are you using to manage dependencies? If it is Gradle or Maven, it should put CSS4J automatically in your classpath or modulepath.

SAXSVGDocumentFactory belongs to echosvg-anim, which declares a dependency on echosvg-svg-dom:

https://github.com/css4j/echosvg/blob/ca972f8d7b24ad08fbbb7662d6daafa78a0edf7c/echosvg-anim/build.gradle#L7

And echosvg-svg-dom depends on echosvg-dom:

https://github.com/css4j/echosvg/blob/ca972f8d7b24ad08fbbb7662d6daafa78a0edf7c/echosvg-svg-dom/build.gradle#L6

which declares a dependency on echosvg-css:

https://github.com/css4j/echosvg/blob/ca972f8d7b24ad08fbbb7662d6daafa78a0edf7c/echosvg-dom/build.gradle#L7

That one carries the CSS4J dependency:

https://github.com/css4j/echosvg/blob/ca972f8d7b24ad08fbbb7662d6daafa78a0edf7c/echosvg-css/build.gradle#L10

All of the dependency chain is transitive, so if you are managing your classpath correctly you should have CSS4J. If your project is modular, similar considerations apply (just look at the relevant module-info files).

If you are more familiar with Maven, you can look at the relevant POM files here:

https://css4j.github.io/maven/io/sf/carte/echosvg-anim/1.0/echosvg-anim-1.0.pom https://css4j.github.io/maven/io/sf/carte/echosvg-svg-dom/1.0/echosvg-svg-dom-1.0.pom https://css4j.github.io/maven/io/sf/carte/echosvg-dom/1.0/echosvg-dom-1.0.pom

Frank-99 commented 10 months ago

it's Ant actually... not to the latest standards I know, but it's what I'm using for this project unfortunately

carlosame commented 10 months ago

it's Ant actually

All you have to do is to add a dependency on css4j and you'll be fine (latest version is 4.2.1). Although if you are managing your classpath manually, one alternative that you have is to build a Uber Jar with all the dependencies:

https://github.com/css4j/echosvg/wiki/Uber-Jar

But my advice would be to migrate to Gradle as soon as you can.

Frank-99 commented 10 months ago

It's a planned migration but it won't happen soon unfortunately...

I've added the css4j jars but now I get this error

java.lang.NoClassDefFoundError: io/sf/carte/doc/xml/dtd/DefaultEntityResolver

I imagine I also need to include xml-dtd also?

carlosame commented 10 months ago

I imagine I also need to include xml-dtd also?

Yes you have to. EchoSVG's DOM uses it to prevent security vulnerabilities while allowing XML entities in the documents (Batik silently erases non-predefined XML entities).

Latest version is 4.2.1.

carlosame commented 10 months ago

I added those errors to the FAQ:

https://github.com/css4j/echosvg/wiki/FAQ#exception-noclassdeffounderror-iosfcartedocstylecssnsacparser

Frank-99 commented 10 months ago

amazing, thank you