Java dom4j org/jaxen/NamespaceContext exception
Asked Answered
I

2

11

I have downloaded dom4j-1.6.1 and added it to java's build path. I am also familiar with java.lang.NoClassDefFoundError: org/saxpath/SAXPathException but I keep getting an exception.

Enclosed a snippet:

public class Parser {
    public static void parse(final String path) throws Exception {
        final SAXReader reader = new SAXReader();
        final Document document = reader.read(new File(path).toURI().toURL());
        if (document == null) return;
        List list = document.selectNodes("/");
        for (Object o : list)
            System.out.println(o);
    }
}

When I run it, I get the following stack trace

Exception in thread "main" java.lang.NoClassDefFoundError: org/jaxen/NamespaceContext
    at org.dom4j.DocumentFactory.createXPath(DocumentFactory.java:230)
    at org.dom4j.tree.AbstractNode.createXPath(AbstractNode.java:207)
    at org.dom4j.tree.AbstractNode.selectNodes(AbstractNode.java:164)
    at Parser.parse(Parser.java:15)
    at Main.main(Main.java:6)
Caused by: java.lang.ClassNotFoundException: org.jaxen.NamespaceContext
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    ... 5 more

Any clue what causes the error?

Indices answered 17/10, 2012 at 11:48 Comment(0)
P
23

The Exception:

java.lang.ClassNotFoundException: org.jaxen.NamespaceContext

Maybe you forgot to include the jaxen.jar in your Java build's path.

For more specific instructions on using SAXReader to parse some XML and loop through the nodes: https://mcmap.net/q/1014444/-extracting-child-nodes-data-from-given-node

Polymorphonuclear answered 17/10, 2012 at 11:51 Comment(1)
Here's a link to jaxen dependency snipets for your pom, etc.: mvnrepository.com/artifact/jaxen/jaxen/1.1.1Lysol
I
2

Found out the solution. I had to download and include jaxen in java's build path.

Indices answered 17/10, 2012 at 11:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.