Pluging development with Apache Batik class loading error.

Answered

Hi,

I'm trying to develop a plugin with apache batik.

I'm getting following error.

Caused by: java.lang.ClassCastException: class org.apache.xerces.jaxp.SAXParserFactoryImpl cannot be cast to class javax.xml.parsers.SAXParserFactory (org.apache.xerces.jaxp.SAXParserFactoryImpl is in unnamed module of loader com.intellij.util.lang.UrlClassLoader @5419f379; javax.xml.parsers.SAXParserFactory is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @565a7edb)

Batik is added as simple dependency,

compile group: 'org.apache.xmlgraphics', name: 'batik-swing', version: '1.12'

2020-04-05 16:34:10,256 [ 8136] ERROR - .wm.impl.ToolWindowManagerImpl - IntelliJ IDEA 2019.3.3 Build #IC-193.6494.35
2020-04-05 16:34:10,256 [ 8136] ERROR - .wm.impl.ToolWindowManagerImpl - JDK: 11.0.5; VM: OpenJDK 64-Bit Server VM; Vendor: JetBrains s.r.o
2020-04-05 16:34:10,256 [ 8136] ERROR - .wm.impl.ToolWindowManagerImpl - OS: Mac OS X

3
3 comments

Samithajay,

SDK provides such classes as well - please verify if you didn't mix the packages importing SAXParserFactory from the different one than expected.

Also, you should consider reusing already available batik packages (wherever it is possible) than bundling your own.

0

Thanks Jakub,

implementation( group: 'org.apache.xmlgraphics', name: 'batik-swing', version: '1.12'){
exclude group: 'xml-apis', module: 'xml-apis-ext'
exclude group: 'org.apache.xmlgraphics', module: 'batik-dom'
}

Did the trick.

0

@Samithajay Hi, I also encountered the same exception when using haraldk/TwelveMonkeys in a plugin project, I posted a discussion here: https://github.com/haraldk/TwelveMonkeys/issues/729#issuecomment-1410060921

I also tried your solution but found no luck, here is my config in build.gradle:

implementation 'com.twelvemonkeys.imageio:imageio-batik:3.9.4'
implementation('org.apache.xmlgraphics:batik-all:1.16'){
exclude group: 'xml-apis', module: 'xml-apis-ext'
exclude group: 'org.apache.xmlgraphics', module: 'batik-dom'
}

And here is the exception message:

Caused by: java.lang.ClassCastException: class org.apache.xerces.jaxp.SAXParserFactoryImpl cannot be cast to class javax.xml.parsers.SAXParserFactory (org.apache.xerces.jaxp.SAXParserFactoryImpl is in unnamed module of loader com.intellij.util.lang.PathClassLoader @61f8bee4; javax.xml.parsers.SAXParserFactory is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @2ca8f5df)
0

Please sign in to leave a comment.