JDOM 2 and ExceptionInInitializerError
The following configuration shows dependencies on JDOM in version 2.0.2 with a Xerces parser version smaller than 2.7:
<dependency> <groupId>org.jdom</groupId> <artifactId>jdom</artifactId> <version>2.0.2</version> </dependency> <dependency> <groupId>xerces</groupId> <artifactId>xercesImpl</artifactId> <version>2.6.2</version> </dependency>
Using this configuration will produce the following stacktrace:
java.lang.ExceptionInInitializerError at org.jdom2.input.SAXBuilder.<init>(SAXBuilder.java:338) at org.jdom2.input.SAXBuilder.<init>(SAXBuilder.java:221) ... Caused by: java.lang.UnsupportedOperationException: This parser does not support specification "null" version "null" at javax.xml.parsers.SAXParserFactory.setSchema(SAXParserFactory.java:419) at org.jdom2.input.sax.XMLReaders.<init>(XMLReaders.java:122) at org.jdom2.input.sax.XMLReaders.<clinit>(XMLReaders.java:95) ... 27 more
To get rid of this problem, simply use a modern version of the libraries:
<dependency> <groupId>org.jdom</groupId> <artifactId>jdom2</artifactId> <version>2.0.4</version> </dependency> <dependency> <groupId>xerces</groupId> <artifactId>xercesImpl</artifactId> <version>2.11.0</version> </dependency>
Please note that the artifact identifier of the JDOM library is jdom2.
Also note that there is no problem if you use
<dependency> <groupId>org.jdom</groupId> <artifactId>jdom</artifactId> <version>2.0.2</version> </dependency>
without an older Xerces version. So the problem described above usually only arises, if an older Xerces version leaks in by a transitive dependency.
JDOM1 side by side with JDOM2
It is no problem if you have JDOM in version 1 and 2 on your classpath. For one this is due to the fact that the designers of this library updated the package structure. But users have to make sure to employ two different artifacts. In this case Maven does not resolve to only one of them.
So this will work as expected (different artifact IDs):
<dependency> <groupId>org.jdom</groupId> <artifactId>jdom2</artifactId> <version>2.0.4</version> </dependency> <dependency> <groupId>org.jdom</groupId> <artifactId>jdom</artifactId> <version>1.1.3</version> </dependency>
And this one, using artifact jdom
instead of jdom2
, does not:
<dependency> <groupId>org.jdom</groupId> <artifactId>jdom</artifactId> <version>2.0.2</version> </dependency> <dependency> <groupId>org.jdom</groupId> <artifactId>jdom</artifactId> <version>1.1.3</version> </dependency>
In the latter case, only one of the artifacts will be on the resolved classpath, class cast exceptions like this will be encountered:
Caused by: java.lang.ClassNotFoundException: org.jdom.JDOMException