wood burning stoves 2.0*
The moose likes Java in General and the fly likes JVM problems.. (can compile, not run classes...) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "JVM problems.. (can compile, not run classes...)" Watch "JVM problems.. (can compile, not run classes...)" New topic
Author

JVM problems.. (can compile, not run classes...)

Veronica Damian
Ranch Hand

Joined: Feb 04, 2006
Posts: 61
not sure where to post this, I hope it's ok here...

All of a sudden I can't run classes.. get typical java.lang.NoClassDefFoundError.. have no idea what happened.. can compile fine but not run classes.. in case my JVM got somehow corrupted uninstalled and installed again, am now on j2sdk1.4.2_11.. reset path (& JAVA_HOME for Tomcat), can compile fine.. but can't run classes... what could this be.. I'm really going crazy here... I have been running JVM on my machine (Win 2000) for over a year, this has never happened..

thank you very much...

-v
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
It's almost certainly a classpath problem. Are you running this from the command line or from an IDE? Using a JAR or are they just out on the local drive? Specifying -cp or do you have an environment variable set?
Veronica Damian
Ranch Hand

Joined: Feb 04, 2006
Posts: 61
from command line.. I don't set classpath, was advised a while ago in usenet java forum NOT to set classpath, and I don't, and it has always worked.. (however: how can it be a classpath problem when I can compile fine? i.e., javac works but not java... many thanks..

-v
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Perhaps something set it for you. Check your control panel.


[Jess in Action][AskingGoodQuestions]
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Well first of all you may not have a direct dependency on what's missing, so it would only show up at runtime. Second, are you compiling from the command line as well? Perhaps a bit more information on what classes are missing and what you're doing would help.
Veronica Damian
Ranch Hand

Joined: Feb 04, 2006
Posts: 61
yes, compiling and running from command line, as I always have..

don't know what you mean by "you may not have a direct dependency on what's missing"

again, thanks........

-v
anshul saxena
Greenhorn

Joined: Oct 20, 2005
Posts: 8
are you including that java file in a package ? if you are then I think you have to remove the package declaration to run it
Veronica Damian
Ranch Hand

Joined: Feb 04, 2006
Posts: 61
nope, no package.. right now for testing purposes just running a very simple hello.java thus:

import java.io.*;
class hello {
public static void main(String args[]) {
System.out.println("hello");
}
}

compiles fine (javac hello.java) but won't run (java hello)

(NoClassDefFoundError should say WHAT class can't be found.. right now don't know if class that can't be found is system API class(es) or class I'm trying to run..)

thank you..

-v
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Are you running both from the same directory and have you verified that hello.class actually exists?
Veronica Damian
Ranch Hand

Joined: Feb 04, 2006
Posts: 61
if I run this: java -verbose hello

get this:

[Opened C:\Program Files\Java\j2re1.4.2_11\lib\rt.jar]
[Opened C:\Program Files\Java\j2re1.4.2_11\lib\sunrsasign.jar]
[Opened C:\Program Files\Java\j2re1.4.2_11\lib\jsse.jar]
[Opened C:\Program Files\Java\j2re1.4.2_11\lib\jce.jar]
[Opened C:\Program Files\Java\j2re1.4.2_11\lib\charsets.jar]
[Loaded java.lang.Object from C:\Program Files\Java\j2re1.4.2_11\lib\rt.jar]
[Loaded java.io.Serializable from C:\Program Files\Java\j2re1.4.2_11\lib\rt.jar]
[Loaded java.lang.Comparable from C:\Program Files\Java\j2re1.4.2_11\lib\rt.jar]
[Loaded java.lang.CharSequence from C:\Program Files\Java\j2re1.4.2_11\lib\rt.ja
r]

etc etc etc

so: it CAN find the system API classes.. I think for some reason JVM can't find class I'm trying to run... but it's there.. why would this be... this has never happened before...

again many thanks..

-v
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
If you are using Windows, type the following command and let us know what the output is:

echo %CLASSPATH%

Perhaps the classpath is set without you knowing. You can also try using the following command to run the program:

java -cp . hello

You should double check to make sure the hello.class file is generated in the directory that you are trying to run it from.

If none of this helps, please explain step-by-step what you do to compile and run the program. Show the full error message you get when you run the program (copy and paste is your friend). If you can provide specific details such as this, we will be able to help you much more efficiently.

Layne


Java API Documentation
The Java Tutorial
Veronica Damian
Ranch Hand

Joined: Feb 04, 2006
Posts: 61
oh my gosh -- when type this it runs ok..

java -cp . hello

what does this mean???
(and yes, class gets generated in same dir where I compile it, I checked..)

echo %CLASSPATH% returns:

c:\tomcat\common\lib\servlet-api.jar

b/c as I indicated before, don't set classpath (except for Tomcat) but as I indicated earlier, this has always worked for me...

many thanks..

-v
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
When you set the CLASSPATH variable in your environment that's what Java uses. Since your current directory is not on the CLASSPATH it can't find the class. I don't see how this could have worked before if the CLASSPATH was set and your classes weren't on it.
Veronica Damian
Ranch Hand

Joined: Feb 04, 2006
Posts: 61
I'm at home now (problem is at work), where I'm running j2sdk1.4.2_09; I don't even have a classpath set, not even for Tomcat.. can compile and run classes fine, regardless of what dir they're in, like I always have been.. Tomcat runs fine.. (this is how it was at work before today..) again many thanks..

-v
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3669
    
  15
If you don't have a classpath set (as at home) java will default to using the current directory.
If you do have a claspath set (as at work) java will use that and will NOT automatically include the current directory.


Joanne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JVM problems.. (can compile, not run classes...)