Java dom4j org / jaxen / NamespaceContext exception

I downloaded dom4j-1.6.1 and added it to the Java build path. I am also familiar with java.lang.NoClassDefFoundError: org / saxpath / SAXPathException , but I get an exception anyway.

Snippet included:

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?

+8
java dom4j
source share
2 answers

An exception:

 java.lang.ClassNotFoundException: org.jaxen.NamespaceContext 

You may have forgotten to include jaxen.jar in your Java build path.

For more specific instructions on using SAXReader for parsing XML data and cyclic transformation through nodes: https://stackoverflow.com/a/168015/168015/ ...

+17
source share

Solution found. I had to download and include jaxen in the Java build path.

+2
source share

All Articles