wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes compile from the terminal ok but error running from terminal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compile from the terminal ok but error running from terminal" Watch "compile from the terminal ok but error running from terminal" New topic
Author

compile from the terminal ok but error running from terminal

Matthew Hartman
Greenhorn

Joined: Jun 27, 2006
Posts: 2
Howdy (I've always wanted to say that (and mean it) from some strange reason),
I'de first like to say that this site is awsome, I love the theme and with all these java experts around, I am wondering if I can hang my hat for a little while (ok, enough with the silliness(SP?), I am aware that it can annoy some grumpy folks after a while :-)).
Ok, down to business. I have the JDK 5.0 release 7 and I have it installed in just one folder away from my lettered drive on Windows XP, for example; (F:\Java). When I edit source code through a text editor and then compile it through the terminal it seems to compile fine and I get a pretty little class file afterwords. However, the trouble comes when I try and run the program with the 'java' command. I get a weird error? message. It reads as follows:

Exception in thread "main" java.lang.NoClassDefFoundError: helloWorld

Of course in this example I used helloWorld as the name of the class that I was trying to run. It's not the code, at least I don't think so because my Mac runs the same code on the same JDK (just a different release, release 5) perfectly. This is not just isolated to one incedent either, it happens every time.
Because of my problem (well not the entire reason, I love eclipse), I am using eclipse and ofcourse with eclipse, everything works perfectly but it just erks me that I can't run my classes/apps from the terminal on my wondows machine. I also have a windows laptop but I am affraid to edit the path variables on that machine as well for fear that I might screw it up in the same way. I am new to the Windows Environment, having come back to windows because of .NET around a year ago but other than that I am used to *nix platforms such as Linux and OS X so my knowledge of windows is slim. Does anyone know what's wrong? I tried to look up: java.lang.NoClassDefFoundError in Java in a Nutshell (latest edition) and I can't seem to find anything about it, as if it doesn't exsist?
Please excuse my ignorance, I am brand spanking new to Java but not to programming (some C (old school, lol I'm 25y/o, what am I doing talking about old school?), .NET, Python and ActionScript) If anyone could help, I would be very greatful and extremely happy. (I'll have my itch scatched, you know the one the is starting to sting a little.) No really, I would be very greatful for a fix to my seemingly small but notoriously big problem. Thanks in advance
You can contact me through this e-mail. learningjava@airspoon.com

Yours Truly,
--Matt
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Most likely you have a problem with your CLASSPATH.

You need to make sure that the directory containing your .class file is in your CLASSPATH.

Try this

java -cp . helloWorld

Are you sure the name of the class is helloWorld?

Remember that you have to have the exact name.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Hello Matt, welcome to the forums.

Try typing in "NoClassDefFoundError" in Google. You'll find that it's one of the pitfalls that almost all new Java programmers hit.

In addition to that, in my signature (below this message) there is a link to The Java Tutorial. It's a very useful online tutorial, and the "Hello World" example there explains exactly what this error means and what you have to do about it.

Have fun with Java.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Matthew Hartman
Greenhorn

Joined: Jun 27, 2006
Posts: 2
Thanks guys,
Keith, so my workspace (whichever that may be) has to be named in my CLASSPATH?

Jesper, I am still going through the links in your signature. I still havent found anything on the issue at hand (but I have just looked through briefly.) I got it to work by putting my workspace or the folder containing my source and class file in my CLASSPATH variable, However, I had to delete the the package name in the source file in order for it to work.

--Matt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: compile from the terminal ok but error running from terminal
 
Similar Threads
basic problem compiling/running code
Terminal Error when Loading .class
Getting JDK 1.3 to work!
Java on the Mac.
newbie needs direction