JDOM 2.X and Maven

XML and Java ? A tumultuous love story…

JDOM is a powerful Java library which aim to ease XML manipulation. It was once included in JSR 102 however the JSR is now withdrawn (more information can be found in the JDOM mailing list).

One of the downside of current JDOM version 2.0.2 is maven integration. When you want to include JDOM in your project, you add the following dependency:


<dependency>
  <groupId>org.jdom</groupId>
  <artifactId>jdom</artifactId>
  <version>2.0.2</version>
</dependency>

 

And JDOM pom.xml references those dependencies :

<dependencies>
  <dependency>
    <groupId>jaxen</groupId>
    <artifactId>jaxen</artifactId>
    <version>1.1.3</version>
    <optional>true</optional>
  </dependency>

  <dependency>
    <groupId>xerces</groupId>
    <artifactId>xercesImpl</artifactId>
    <version>2.10.0</version>
    <optional>true</optional>
  </dependency>

  <dependency>
    <groupId>xalan</groupId>
    <artifactId>xalan</artifactId>
    <version>2.7.1</version>
    <optional>true</optional>
  </dependency>
</dependencies>

 

Now if you try to perform mvn install, you will face one of the following errors :

  • The following artifacts could not be resolved: maven-plugins:maven-cobertura-plugin:plugin:1.3, maven-plugins:maven-findbugs-plugin:plugin:1.3.1, Failure to find maven-plugins:maven-cobertura-plugin:plugin:1.3 in …

This error is caused by a broken artifact on Jaxen 1.1.3. The work-around is to use the “exclusions” tags in order to avoid loading of unfound dependencies.

<dependency>
  <groupId>jaxen</groupId>
  <artifactId>jaxen</artifactId>
  <version>1.1.3</version>
  <optional>true</optional>
  <exclusions>
    <exclusion>
      <groupId>maven-plugins</groupId>
      <artifactId>maven-cobertura-plugin</artifactId>
    </exclusion>
    <exclusion>
      <groupId>maven-plugins</groupId>
      <artifactId>maven-findbugs-plugin</artifactId>
    </exclusion>
  </exclusions>
</dependency>

 

 

java.lang.ExceptionInInitializerError
    at org.jdom2.input.SAXBuilder.(SAXBuilder.java:338)
    at org.jdom2.input.SAXBuilder.(SAXBuilder.java:221)
    at [...]

Caused by: java.lang.UnsupportedOperationException: This parser does not support specification "null" version "null"

    at javax.xml.parsers.SAXParserFactory.setSchema(SAXParserFactory.java:421)
    at org.jdom2.input.sax.XMLReaders.(XMLReaders.java:122)
    at org.jdom2.input.sax.XMLReaders.(XMLReaders.java:95)
    ... 30 more

 

This error is caused by an old version of xercesImpl specified in the resolved dependencies. Once again, we will use the “exclusions” tag to avoid this error.

<dependency>
  <groupId>jaxen</groupId>
  <artifactId>jaxen</artifactId>
  <version>1.1.3</version>
  <optional>true</optional>

  <!-- Use JDK xerces version -->
  <exclusions>
    <exclusion>
      <groupId>xerces</groupId>
      <artifactId>xercesImpl</artifactId>
    </exclusion>
  </exclusions>
</dependency>

 

This should not work if your JDK is lesser than 1.5.

In summary, here is the depency set I currently use for JDOM 2.0.2 :

<dependency>
  <groupId>org.jdom</groupId>
  <artifactId>jdom</artifactId>
  <version>2.0.2</version>
</dependency>

<dependency>
  <groupId>jaxen</groupId>
  <artifactId>jaxen</artifactId>
  <version>1.1.3</version>
  <exclusions>
    <!-- Use JDK xerces version -->
    <exclusion>
      <groupId>xerces</groupId>
      <artifactId>xercesImpl</artifactId>
    </exclusion>
    <exclusion>
      <groupId>maven-plugins</groupId>
      <artifactId>maven-cobertura-plugin</artifactId>
    </exclusion>
    <exclusion>
      <groupId>maven-plugins</groupId>
      <artifactId>maven-findbugs-plugin</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
</dependency>

 

Advertisement

One thought on “JDOM 2.X and Maven

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s