Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2006

Tip: Looking for answers? Try searching our database.

JVM problems...

Thread view: 
Frances - 23 Mar 2006 19:20 GMT
java won't run...  get typical java.lang.NoClassDefFoundError.. have no
 idea what happened.. 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..

thank you..
Frances
Roedy Green - 23 Mar 2006 21:40 GMT
>NoClassDefFoundError

for a list of many possible causes see
http://mindprod.com/jgloss/caq.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Frances - 23 Mar 2006 22:17 GMT
>>NoClassDefFoundError
>
> for a list of many possible causes see
> http://mindprod.com/jgloss/caq.html

thank you Roedy.. let's see..

1. not this one, since am not running in browser (compiling/running
stand-alone's in command-line..)

2.  'class mentioned' is class you're trying to run right? for testing
purposes am trying to run a hello.java, very simple, thus:

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

compiles (javac hello.java) but won't run (java hello)
   NONE of the other .java's I have in my HD is now running (in all
cases, compiled again, b/c just re-installed JVM, but they won't run...)

again, as have been advised many times here do not have a classpath set,
this has always worked for me (but how? it says here
http://java.sun.com/j2se/1.3/docs/tooldocs/win32/classpath.html

that if you don't set classpath java looks for it in same directory of
class you're trying to run ("current directory"..) I have always been
able to compile/run classes from anywhere in my HD w/o having set
classpath..  ?????

I have been running JVM on my machine (W2000) for over a year now, all
of a sudden my classes won't run.. this is truly bizarre...

3. can't do diagnostic, as can't run any code....;)

4. nothing serialized involved.

5. don't have classpath set (except for Tomcat, thus:
      CLASSPATH=c:\tomcat\common\lib\servlet-api.jar)

just tried running this:

   java hello -classpath c:\j2sdk1.2_11\jre\lib\rt.jar

but got exact same error: Exception in thread "main"
java.lang.NoClassDefFoundError: hello

I really don't get this...  (rt.jar is where system API is, right? also,
I doubt it's a classpath problem b/c can compile fine..)

it seems JVM can't find the class I'm trying to run, but it's there, I
can see it...  WEIRD.....

thank you Roedy....    :(
Frances - 23 Mar 2006 22:22 GMT
>>> NoClassDefFoundError
>>
[quoted text clipped - 53 lines]
>
> thank you Roedy....    :(

NoClassDefFoundError should say WHAT class can't be found.. right don't
know if class that can't be found is system API class(es) or class I'm
trying to run....
James Westby - 24 Mar 2006 00:08 GMT
>>>> NoClassDefFoundError
>>>
>>> for a list of many possible causes see
>>> http://mindprod.com/jgloss/caq.html
>>
>> thank you Roedy.. let's see..
[snip]

>> compiles (javac hello.java) but won't run (java hello)
>>    NONE of the other .java's I have in my HD is now running (in all
[quoted text clipped - 11 lines]
>> I have been running JVM on my machine (W2000) for over a year now, all
>> of a sudden my classes won't run.. this is truly bizarre...
[snip]
>> 5. don't have classpath set (except for Tomcat, thus:
>>       CLASSPATH=c:\tomcat\common\lib\servlet-api.jar)
>>
>> just tried running this:
>>
>>    java hello -classpath c:\j2sdk1.2_11\jre\lib\rt.jar

This will pass -classpath ... as an argument to your code, put it before
your class name.

Also you haven't included the current directory, it should be

java -classpath .;c:\j2sdk...

(note .;)

If this works then it is a global CLASSPATH set to something odd.

Try

echo %CLASSPATH%

it should give you a blank line (I think).

>> but got exact same error: Exception in thread "main"
>> java.lang.NoClassDefFoundError: hello

This implies that it can't find /your/ class, not the rt.jar ones.

>> I really don't get this...  (rt.jar is where system API is, right?
>> also, I doubt it's a classpath problem b/c can compile fine..)

Compiling doesn't use CLASSPATH

> NoClassDefFoundError should say WHAT class can't be found..
It does, "hello".

James
Frances - 24 Mar 2006 00:29 GMT
>>>>> NoClassDefFoundError
>>>>
[quoted text clipped - 62 lines]
>
> James

thank you very much.. it turns out if I run it like this..

   java -cp . hello

it runs fine..  what does this mean? that java is finding rt.jar in
CURRENT DIR?  this doesn't make sense...

also to humor everyone who says I should set classpath, I set the
classpath thus:

 C:\j2sdk1.4.2_11\jre\lib\rt.jar;.;c:\tomcat\common\lib\servlet-api.jar
     (and restarted machine, although don't know if this is necessary..)

but it won't run either if I do 'java hello', only if i do

  java -cp . hello

can somebody pls explain this..

  (yes, I also get feeling it can't find MY class (not rt.jar..)
but WHY.. class does get put in same dir where src code is that I'm
compiling..  have been doing all this for over a year now, why is JVM
acting so wacky all of a sudden?  my tomcat won't start either now..
this is freaking me out... have no idea what's going on here...)

many thanks...  Frances
James Westby - 24 Mar 2006 01:53 GMT
[snip]
>> Also you haven't included the current directory, it should be
>>
[quoted text clipped - 9 lines]
>>
>> it should give you a blank line (I think).

[snip]
>> Compiling doesn't use CLASSPATH

[snip]
> thank you very much.. it turns out if I run it like this..
>
>    java -cp . hello
>
> it runs fine..  what does this mean? that java is finding rt.jar in
> CURRENT DIR?  this doesn't make sense...

No it means it is finding your class (hello) in the current dir i.e.
where it is. It knows where rt.jar is, you don't need to worry about that.

> also to humor everyone who says I should set classpath, I set the
> classpath thus:
>
>  C:\j2sdk1.4.2_11\jre\lib\rt.jar;.;c:\tomcat\common\lib\servlet-api.jar
>      (and restarted machine, although don't know if this is necessary..)

How did you set this?

> but it won't run either if I do 'java hello',

What does echo %CLASSPATH% show you?

>  only if i do
>
>   java -cp . hello
>
> can somebody pls explain this..

I don't think CLASSPATH is set like you think it is, and I don't think
it works like you think it does.

>   (yes, I also get feeling it can't find MY class (not rt.jar..)
> but WHY.. class does get put in same dir where src code is that I'm
> compiling..  

But compiling doesn't use the classpath, I don't see why this matters.

> have been doing all this for over a year now, why is JVM
> acting so wacky all of a sudden?

Because you changed something. Did this occur just after you installed
Tomcat?

> my tomcat won't start either now..

How are you starting it? What is the error? You shouldn't have to set
CLASSPATH to get Tomcat to run.

> this is freaking me out... have no idea what's going on here...)
>
> many thanks...  Frances

James
Frances - 24 Mar 2006 03:31 GMT
> [snip]
>
[quoted text clipped - 27 lines]
> No it means it is finding your class (hello) in the current dir i.e.
> where it is. It knows where rt.jar is, you don't need to worry about
that.

so the classpath is for the class I'm running and not for rt.jar?  I
didn't know that..

>> also to humor everyone who says I should set classpath, I set the
>> classpath thus:
[quoted text clipped - 3 lines]
>>
> How did you set this?

in Control Panel, where you set env vars (where you set path, JAVA_HOME
for Tomcat, etc..)

>> but it won't run either if I do 'java hello',
>
> What does echo %CLASSPATH% show you?
C:\j2sdk1.4.2_11\jre\lib\rt.jar;.;c:\tomcat\common\lib\servlet-api.jar
now that I set it..

>>  only if i do
>>
[quoted text clipped - 10 lines]
>
> But compiling doesn't use the classpath,
oh? I didn't know this..

I don't see why this matters.

>> have been doing all this for over a year now, why is JVM acting so
>> wacky all of a sudden?
>
> Because you changed something. Did this occur just after you installed
> Tomcat?

I installed Tomcat a long time ago..  have not changed anything..

>> my tomcat won't start either now..
>
> How are you starting it? What is the error? You shouldn't have to set
> CLASSPATH to get Tomcat to run.

no error, the shell appears very briefly then disappears...

>> this is freaking me out... have no idea what's going on here...)
>>
>> many thanks...  Frances
>
> James

am at home now, where am on j2sdk1.4.2_09; don't even have a classpath
set, not even for tomcat, but can compile and run classes ok, regardless
of what dir they're in, like I always have been able to, and at work
this always worked fine too, until today..  again thank you very much..
Roedy Green - 24 Mar 2006 06:57 GMT
> >> this is freaking me out... have no idea what's going on here...)
> >>
> >> many thanks...  Frances

Read the background material to explain the classpath.  See
http://mindprod.com/jgloss/classpath.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 24 Mar 2006 06:53 GMT
>thank you very much.. it turns out if I run it like this..
>
>    java -cp . hello
>
>it runs fine..  what does this mean? that java is finding rt.jar in
>CURRENT DIR?  this doesn't make sense...

java can find its own files by independent means. Back in Java 1.0 you
had to help it with the classpath, but that has not been true a long
time.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Frances - 24 Mar 2006 15:06 GMT
>>thank you very much.. it turns out if I run it like this..
>>
[quoted text clipped - 6 lines]
> had to help it with the classpath, but that has not been true a long
> time.

got rid of classpath altogether; now it's working again...  have no idea
what caused the problem.. this is bizarre...  so: b/c yesterday all of a
sudden it stopped working set classpath (which I had never done before)
it still wouldn't work.. this morning came in, got rid of classpath
altogether, and now all of a sudden it works again...  really weird..
problem am having now is my Tomcat won't start (don't even get errors,
when run startup.bat Tomcat shell appears very briefly and disappears...
so have no idea how I will deal with this one.. am begining to believe
this all must have been some fluke thing in my machine..)  thank you
very much..
James Westby - 24 Mar 2006 15:09 GMT
>>> thank you very much.. it turns out if I run it like this..
>>>
[quoted text clipped - 17 lines]
> this all must have been some fluke thing in my machine..)  thank you
> very much..

Look in the logs. That will tell you what the error is.

James
Roedy Green - 24 Mar 2006 19:04 GMT
>. am begining to believe
>this all must have been some fluke thing in my machine..)

Before you go founding a new religion based on these miracles, please
read the essay I gave you http://mindprod.com/jgloss/classpath.html

This sort of craziness is normal and, believe it or not, has a
rational explanation. Nearly every Java programmer before  you went
through this same bafflement.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 24 Mar 2006 06:56 GMT
>  C:\j2sdk1.4.2_11\jre\lib\rt.jar;.;c:\tomcat\common\lib\servlet-api.jar
>      (and restarted machine, although don't know if this is necessary..)

If you are using windows type
set and check all the environment variables. You may not be
permanently setting them. See
http://mindprod.com/jgloss/environment.html

you don't need rt.jar on the classpath and you likely don't need that
tomcat jar either. Read the Tomcat install instructions what to do.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Nigel Wade - 24 Mar 2006 11:02 GMT
> thank you very much.. it turns out if I run it like this..
>
[quoted text clipped - 14 lines]
>
> can somebody pls explain this..

The classpath separator is a : not a ;. It's not a Windows path.

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Oliver Wong - 23 Mar 2006 23:28 GMT
> just tried running this:
>
>    java hello -classpath c:\j2sdk1.2_11\jre\lib\rt.jar
>
> but got exact same error: Exception in thread "main"
> java.lang.NoClassDefFoundError: hello

   Not sure, but assuming that "hello" is in the current directory, and not
in rt.jar, you should probably specify that the current directory is also
part of the classpath.

   Also, are you sure you meant "hello", and not "Hello", for example?
Class names are case sensitive.

   - Oliver
Roedy Green - 24 Mar 2006 00:22 GMT
>it seems JVM can't find the class I'm trying to run, but it's there, I
>can see it...  WEIRD.....

try java -version to see if you are running the JVM you think you are.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Frances - 24 Mar 2006 03:33 GMT
>>it seems JVM can't find the class I'm trying to run, but it's there, I
>>can see it...  WEIRD.....
>
> try java -version to see if you are running the JVM you think you are.

it's j2sdk1.4.2_11, I installed it today, since thought there was
something wrong with the one I had..   thank you..


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.