I am new to JDom, I am trying to use XPath to access my XML file. My code is as follows:
public static void main(String[] args) throws Exception { Document doc = new SAXBuilder().build("file.xml"); XPath x = XPath.newInstance("xpath");
I have already imported the org.jdom.xpath.XPath class. When I use javac to compile the class, it did not throw any errors, however, when I try to run the program, it gives the following error message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaxen/NamespaceContext at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at org.jdom.xpath.XPath.newInstance(XPath.java:134) at myclassname.main(xmlTohtml.java:18) Caused by: java.lang.ClassNotFoundException: org.jaxen.NamespaceContext at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) ... 4 more
Did I miss something? Any help would be greatly appreciated!
I add jaxen and dom4j to my .cshrc file, which is located directly under my home directory, and the two jar files are in the same directory.
setenv CLASSPATH ${CLASSPATH}:/homedirectory/jaxen-1.1.1.jar setenv CLASSPATH ${CLASSPATH}:/homedirectory/dom4j-1.6.1.jar
When I try to execute this command from the command line, it throws new exceptions ....
Exception in thread "main" java.lang.NoClassDefFoundError: : Caused by: java.lang.ClassNotFoundException: : at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
By the way, the imported classes in my program:
import java.util.Iterator; import org.jdom.Document; import org.jdom.Element; import org.jdom.input.SAXBuilder; import org.jdom.Namespace; import org.jdom.xpath.XPath;
java dom sax jdom
Michael
source share