• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Runtime problem in Command Prompt

 
thomas jacob
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Regards
Thomas
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which class does it not find? And where does "SAXTreeViewer" come from? It does not seem to be in your classpath. If it's in your current directory, have you tried

java -classpath .;%CLASSPATH% SAXTreeViewer
[ February 05, 2006: Message edited by: Ulf Dittmer ]
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11866
194
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thomas,

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.

Regards, Andrew
 
thomas jacob
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the error I get


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)
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15219
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
thomas jacob
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Regards
Thomas
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post your CLASSPATH
 
thomas jacob
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
classpath: 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;
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
thomas jacob
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My current working directoy is the bin directory which contains the SAXTreeViewer class
 
thomas jacob
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;


classpath has the .: also to search the current directory also
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My current working directoy is the bin directory which contains the SAXTreeViewer class

That's the wrong place to keep the SAXTreeViewer class, because the error says
Exception in thread "main" java.lang.NoClassDefFoundError: SAXTreeViewer (wrong
name: javaxml2/SAXTreeViewer)

The class has a "package javaxml2;" statement, so it should be in a subdirectory called javaxml2 (or, alternatively, remove the package statement).
 
thomas jacob
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks mate I tried running it as java SAXTreeViewer from javaxml2 directory.
I moved above the javaxml2 directory and did a java javaxml2.SAXTreeViewer


Cheers
Jigo
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic