aspose file tools*
The moose likes Java in General and the fly likes Runtime problem in Command Prompt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Runtime problem in Command Prompt" Watch "Runtime problem in Command Prompt" New topic
Author

Runtime problem in Command Prompt

thomas jacob
Ranch Hand

Joined: May 19, 2005
Posts: 91
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
Marshal

Joined: Mar 22, 2005
Posts: 42631
    
  65
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 ]

Ping & DNS - my free Android networking tools app
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11509
    
  95

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


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
thomas jacob
Ranch Hand

Joined: May 19, 2005
Posts: 91
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

Joined: Aug 16, 2005
Posts: 14350
    
  22

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).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
thomas jacob
Ranch Hand

Joined: May 19, 2005
Posts: 91
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

Please post your CLASSPATH


[My Blog]
All roads lead to JavaRanch
thomas jacob
Ranch Hand

Joined: May 19, 2005
Posts: 91
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
Marshal

Joined: Mar 22, 2005
Posts: 42631
    
  65
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

Joined: May 19, 2005
Posts: 91
My current working directoy is the bin directory which contains the SAXTreeViewer class
thomas jacob
Ranch Hand

Joined: May 19, 2005
Posts: 91
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
Marshal

Joined: Mar 22, 2005
Posts: 42631
    
  65
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

Joined: May 19, 2005
Posts: 91
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Runtime problem in Command Prompt