问题
I'm trying to use batik with grails to render some SVG stuff to PNG on the server.
I'm getting the following error in IntelliJ when I add the dependencies to BuildConfig and then tell IntelliJ to load the changes:
/Library/Java/JavaVirtualMachines/1.6.0_33-b03-424.jdk/Contents/Home/bin/java -Dgrails.home=/Applications/Dev/grails-2.1.0 -Dbase.dir=/Users/greg/Documents/development/git/liftyourgame-grails/webapp -Dtools.jar=/Library/Java/JavaVirtualMachines/1.6.0_33-b03-424.jdk/Contents/Home/lib/tools.jar -Dgroovy.starter.conf=/Applications/Dev/grails-2.1.0/conf/groovy-starter.conf -Xmx512M -XX:MaxPermSize=192m -javaagent:/Applications/IntelliJ IDEA 11.app/plugins/Grails/lib/grails_rt.jar -Dprint.grails.settings=true -Dfile.encoding=UTF-8 -classpath /Applications/Dev/grails-2.1.0/lib/org.codehaus.groovy/groovy-all/jars/groovy-all-1.8.6.jar:/Applications/Dev/grails-2.1.0/dist/grails-bootstrap-2.1.0.jar org.codehaus.groovy.grails.cli.support.GrailsStarter --main org.codehaus.groovy.grails.cli.GrailsScriptRunner --conf /Applications/Dev/grails-2.1.0/conf/groovy-starter.conf help
| Loading Grails 2.1.0
| Configuring classpath
| Error Error executing script Help: loader constraint violation: when resolving overridden method "org.apache.tools.ant.helper.ProjectHelper2$RootHandler.setDocumentLocator(Lorg/xml/sax/Locator;)V" the class loader (instance of org/codehaus/groovy/grails/cli/support/GrailsRootLoader) of the current class, org/apache/tools/ant/helper/ProjectHelper2$RootHandler, and its superclass loader (instance of <bootloader>), have different Class objects for the type org/xml/sax/Locator used in the signature (Use --stacktrace to see the full trace)
IDEA hook: Grails not found!
| Error java.lang.NullPointerException
| Error at org.jetbrains.groovy.grails.rt.Agent$2.run(Agent.java:88)
| Error at java.lang.Thread.run(Thread.java:680)
Grails clean gives a similar result.
BuildConfig.groovy contains among other things:
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
excludes 'slf4j-log4j12', 'xml-apis', 'xalan', 'xml-apis-ext', 'commons-logging', 'commons-io'
}
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
repositories {
inherits true // Whether to inherit repository definitions from plugins
grailsPlugins()
grailsHome()
grailsCentral()
mavenCentral()
}
dependencies {
compile "org.jadira.usertype:usertype.jodatime:1.9"
compile "org.imgscalr:imgscalr-lib:4.0"
compile("org.apache.xmlgraphics:batik-svg-dom:1.7")
{
excludes 'batik-xml', 'batik-dom', 'commons-javaflow',
'avalon-framework-api', 'avalon-framwork-impl',
'batik-css', 'batik-gvt', 'batik-script',
'slf4j-log4j12', 'xml-apis', 'xml-apis-ext', 'log4j', 'xercesImpl', 'xalan',
'antlr', 'commons-beanutils', 'commons-collections', 'commons-logging', 'xmlParserAPIs',
'ant', 'mondrian', 'groovy-all', 'saaj-api', 'servlet-api', 'spring-core', 'bsh',
'spring-beans', 'jaxen', 'persistence-api', 'jdtcore', 'bcmail-jdk16', 'bcprov-jdk16',
'bctsp-jdk16', 'bcmail-jdk14', 'bcprov-jdk14', 'bctsp-jdk14', 'xmlbeans'
}
}
The pom for batik-svg-dom includes some of the other batik jars as well as xml-apis and xml-apis-ext. My research has shown that the xml dependencies can cause trouble under grails and as they are not required beyond jdk 1.4 they have been excluded.
I've also tried to track down other org.xml.sax.Locator instances using IntelliJs tools but the only instance found is in: /Applications/Dev/grails-2.1.0/lib/org.apache.ant/ant-launcher/jars/ant-launcher-1.8.2.jar!/org/apache/tools/ant/launch/Locator.class
I've also tried grails refresh-dependencies and I've tried removing the .grails folder but I always get the same result.
Any ideas please?
回答1:
The issue seems to be that Batik includes a version of xml-apis that clashes with the one now included in the JDK. (http://grails.1312388.n4.nabble.com/Problems-integrating-batik-with-grails-project-td4632728.html) So, it's a matter of excluding 'xml-apis' as you have done already. However, since so many of Batik's jars have transitive dependencies on xml-apis, it is hard to get Grails to exclude it. Here's what eventually worked for me:
compile("org.apache.xmlgraphics:fop:0.94",
"org.apache.xmlgraphics:batik-transcoder:1.7",
"org.apache.xmlgraphics:batik-codec:1.7",
"org.apache.xmlgraphics:batik-awt-util:1.7",
"org.apache.xmlgraphics:batik-bridge:1.7",
"org.apache.xmlgraphics:batik-dom:1.7",
"org.apache.xmlgraphics:batik-gvt:1.7",
"org.apache.xmlgraphics:batik-svg-dom:1.7",
"org.apache.xmlgraphics:batik-svggen:1.7",
"org.apache.xmlgraphics:batik-util:1.7",
"org.apache.xmlgraphics:batik-xml:1.7",
"org.apache.xmlgraphics:batik-anim:1.7",
"org.apache.xmlgraphics:batik-css:1.7",
"org.apache.xmlgraphics:batik-ext:1.7",
"org.apache.xmlgraphics:batik-js:1.7",
"org.apache.xmlgraphics:batik-parser:1.7",
"org.apache.xmlgraphics:batik-script:1.7",
"org.apache.xmlgraphics:xmlgraphics-commons:1.2",
"commons-logging:commons-logging:1.0.4",
"org.apache.avalon.framework:avalon-framework-api:4.3.1",
"org.apache.avalon.framework:avalon-framework-impl:4.3.1",
"xalan:xalan:2.6.0",
"xml-apis:xml-apis-ext:1.3.04"
){
transitive = false
}
This is basically a whitelist of the Batik jars I want to include. Since transitive = false, transitive dependencies are ignored.
However, I still can't actually get Batik to work - there seems to be a secondary issue where org.apache.batik.dom.svg.SVGOMDocument is missing even though the required jars which contain that class are deployed in my war.
Did you find another working solution?
来源:https://stackoverflow.com/questions/11822681/batik-with-grails-giving-sax-clash