I am trying to run a java program for parsing a XML document using SAX APIs. I added the location of the SAX API jar files in the environment CLASSPATH: C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar;C:\Program Files\Altova\XMLSpy2006\Xerces Parser\xerces-2_7_1\resolver.jar;C:\Program Files\Altova\XMLSpy2006\Xerces Parser\xerces-2_7_1\xercesImpl.jar;C:\Program Files\Altova\XMLSpy2006\Xerces Parser\xerces-2_7_1\xml-apis.jar;
The program compiled successfully in command prompt. But when I run the program under command prompt, using this command java SAXTreeViewer it throws a runtime error NoClassDefFoundError. It is not finding the classfiles in the jar file. I tried running the same program throught the Eclipse IDE, by adding the SAX API jar file location in the java build path under the Libraries tab of Eclipse IDE. I ran without an error. I want to avoid using the Eclipse IDE as much as possible to get my basics right. how do I run the program successfully in the Command prompt?. I don't understand why during the class files in the jar files cannot be referenced from the CLASSPATH variable.
Please do not post the same question in more than one forum. The copy that was in the Sun Certified Java Developer forum has been deleted. The Sun Certified Java Developer forum is designed for discussions related to the the SCJD certification process and assignment.
D:\eclipse\workspace\javaxml\ch03\src>java -classpath "%classpath%" SAXTreeViewe r Exception in thread "main" java.lang.NoClassDefFoundError: SAXTreeViewer
D:\eclipse\workspace\javaxml\ch03\src\javaxml2>java -classpath "%classpath%" SAX TreeViewer Exception in thread "main" java.lang.NoClassDefFoundError: SAXTreeViewer (wrong name: javaxml2/SAXTreeViewer) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source)
So have you tried what Ulf told you: add the current directory (".") to the classpath?
Where does class SAXTreeParser come from? Is that your own program? Is it in the default package? (If not, you need to specify the package name on the command line, for example: com.mystuff.SAXTreeParser).
The SAXTreeViewer is my own program. The Class is residing in the path D:\eclipse\workspace\javaxml\bin\javaxml2\SAXTreeViewer.class. I ran the class under command prompt from the javaxml2 directory and also tried running from the root (bin directory). The SAXTreeViewer class is a part of the javaxml2 package which has only this single class. I even have all the required jars and current directory in the CLASSPATH Variable. The program is running on Eclipse IDE fine. I suspect there is some wrong with the JVM, not able to load the class. ANYBODY HELPPPPPPPPPP
D:\eclipse\workspace\javaxml\bin is not in your classpath. Eclipse most likely has a different notion of what the classpath is than the standalone JVM, so it doesn't mean much that it's running inside of it.
Joined: May 19, 2005
My current working directoy is the bin directory which contains the SAXTreeViewer class