I get the following exception when trying to access any nodes of a parsed xml document on dom4j:
Exception in thread \"main\" java.lang.NoClassDefFoundError: or
A java.lang.NoClassDefFoundError
is thrown by the JVM when a dependency that was available at the time a particular class was compiled cannot be found on the classpath when the class is loaded for use by the JVM.
How are you invoking the parser code? Check and make sure that all the DOM4J dependencies in the lib
folder of the DOM4J distribution (jaxen, jaxme-api etc) are on the classpath.
If you are invoking the parser from the command line you can use the -classpath
option:
java -classpath C:\myjars\jar1.jar;C:\myjars\jar1.jar
If you are invoking the parser from Ant for example use the <classpath>
tag:
<classpath>
<pathelement path="C:\myjars\jar1.jar"/>
<pathelement path="C:\myjars\jar2.jar"/>
</classpath>
Your xpath expressions are not even being evaluated so you should stoptweaking those until you have sorted out your classpath issues.
So xpath works if I include jaxen-1.1-beta-6.jar in addition to the jdom4 jar. Note the jaxen-1.1.1.jar does not work. If you have a classdef error from jdom look at their dependencies and make sure you are using their approved jars, (which for the 1.6.1 version is now often an older release of the jar). Hope this helps anyone with a similar problem. Thanks again for everyone's help!
In the unlikely event that anyone else should encounter this issue in JBoss Fuse I'll add what solved my problem:
You will need to wrap both the jaxen- and the dom4j jars as OSGi-bundles.
osgi:install -s wrap:mvn:jaxen/jaxen/1.1-beta-6
osgi:install -s wrap:mvn:dom4j/dom4j/1.6.1
In that particular order, as I found out the hard way. I had already wrapped the dom4j jar and simply adding the jaxen jar after the fact was unsuccessful.
You should add jaxen library to your class path.
EDIT: Actually original dom4j distribution contains jaxen.jar in that as well as all other dependencies.
If you're using mvn2, the following will work with dom4j 1.6.1:
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1.1</version>
</dependency>
That being said, I hope they fix their pom and save everyone this trouble.