For Programmers: Free Programming Magazines  


Home > Archive > Java Help > March 2006 > JVM problems...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author JVM problems...
Frances

2006-03-23, 10:04 pm

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

2006-03-23, 10:04 pm

On 23 Mar 2006 19:20:49 +0100, Frances <fdr58@yahoo.com> wrote, quoted
or indirectly quoted someone who said :

>NoClassDefFoundError


for a list of many possible causes see
http://mindprod.com/jgloss/caq.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Frances

2006-03-23, 10:04 pm

Roedy Green wrote:
> On 23 Mar 2006 19:20:49 +0100, Frances <fdr58@yahoo.com> wrote, quoted
> or indirectly quoted someone who said :
>
>
>
>
> 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/t.../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

2006-03-23, 10:04 pm

Frances wrote:
> Roedy Green wrote:
>
>
>
> 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/t.../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.... :(
>


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





Oliver Wong

2006-03-23, 10:04 pm


"Frances" <fdr58@yahoo.com> wrote in message
news:44231043$0$15795$14726298@news.sunsite.dk...
>
> 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

James Westby

2006-03-23, 10:04 pm

Frances wrote:
> Frances wrote:
[snip][color=darkred]
[snip][color=darkred]

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).
[color=darkred]

This implies that it can't find /your/ class, not the rt.jar ones.[color=darkred]

Compiling doesn't use CLASSPATH
[color=darkred]
>
> NoClassDefFoundError should say WHAT class can't be found..

It does, "hello".


James
Roedy Green

2006-03-23, 10:04 pm

On Thu, 23 Mar 2006 16:17:50 -0500, Frances <fdr58@yahoo.com> wrote,
quoted or indirectly quoted someone who said :

>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.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Frances

2006-03-23, 10:04 pm

James Westby wrote:
> Frances wrote:
>
>
> [snip]
>
>
> [snip]
>
>
> 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).
>
>
>
> This implies that it can't find /your/ class, not the rt.jar ones.
>
>
>
> Compiling doesn't use CLASSPATH
>
>
> It does, "hello".
>
>
> 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

2006-03-23, 10:04 pm

Frances wrote:
> James Westby wrote:

[snip]
[snip][color=darkred]
[snip][color=darkred]
> 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

2006-03-23, 10:04 pm

James Westby wrote:
> Frances wrote:
>
>
> [snip]
>
> [snip]
>
> [snip]
>
>
>
> 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..
>
> How did you set this?


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

>
>
> 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..
>
>
> I don't think CLASSPATH is set like you think it is, and I don't think
> it works like you think it does.
>
>
>
> But compiling doesn't use the classpath,

oh? I didn't know this..

I don't see why this matters.
>
>
>
> Because you changed something. Did this occur just after you installed
> Tomcat?


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

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

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

Frances

2006-03-23, 10:04 pm

Roedy Green wrote:
> On Thu, 23 Mar 2006 16:17:50 -0500, Frances <fdr58@yahoo.com> wrote,
> quoted or indirectly quoted someone who said :
>
>
>
>
> 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..


Roedy Green

2006-03-24, 4:14 am

On Thu, 23 Mar 2006 18:29:47 -0500, Frances <fdr58@yahoo.com> wrote,
quoted or indirectly quoted someone who said :

>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.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green

2006-03-24, 4:14 am

On Thu, 23 Mar 2006 18:29:47 -0500, Frances <fdr58@yahoo.com> wrote,
quoted or indirectly quoted someone who said :

> 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.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green

2006-03-24, 4:14 am

On 24 Mar 2006 03:31:59 +0100, Frances <fdr58@yahoo.com> wrote, quoted
or indirectly quoted someone who said :
[color=darkred]

Read the background material to explain the classpath. See
http://mindprod.com/jgloss/classpath.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Nigel Wade

2006-03-24, 4:14 am

Frances wrote:

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


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

--
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
Frances

2006-03-24, 7:10 pm

Roedy Green wrote:
> On Thu, 23 Mar 2006 18:29:47 -0500, Frances <fdr58@yahoo.com> wrote,
> quoted or indirectly quoted someone who said :
>
>
>
>
> 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.


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

2006-03-24, 7:10 pm

Frances wrote:
> Roedy Green wrote:
>
> 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..


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


James
Roedy Green

2006-03-24, 7:10 pm

On Fri, 24 Mar 2006 09:06:56 -0500, Frances <fdr58@yahoo.com> wrote,
quoted or indirectly quoted someone who said :

>. 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.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com