Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Veronica Damian
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps something set it for you. Check your control panel.
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you running both from the same directory and have you verified that hello.class actually exists?
 
Veronica Damian
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Veronica Damian
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic