aspose file tools*
The moose likes Beginning Java and the fly likes setting classpath in 2000 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "setting classpath in 2000" Watch "setting classpath in 2000" New topic
Author

setting classpath in 2000

mdotting
Greenhorn

Joined: Jan 02, 2002
Posts: 10
Howdy, I've recently upgraded my OS to 2000. I installed jdk1.3 directly to my C: drive and went into settings and appended .;C:\jdk1.3\bin to the end of the path variable. When I go to do a test program I get something weird. My very simple Test.java program compiles fine. But when I go to execute it, it says:
Exception in thread "main" java.lang.NoClassDefFoundError:Test
Does this have to do with the classpath? I thought that if your classpath was wrong you wouldn't even be able to compile it in the first place. So frustrating, I'm a SCJP and I STILL have problems with classpaths!!! Any suggestions on what's wrong are greatly appreciated. Thanks, Mike.
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
My advice to you is to abandon relying on the CLASSPATH environment variable being set. Set it manually from the command line, or in a batch file, for the application you are running; then create a shortcut to that batch file and you can double-click your way to classpath freedom...but I digress.
You probably don't have the current directory in your classpath: "./". Even if you are launching java from a working directory that contains the class with the main method you want to invoke, it can't "see" your class if it's not in the classpath.
Rob


Rob
SCJP 1.4
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9052
    
  12
Originally posted by mdotting:
But when I go to execute it, it says:
Exception in thread "main" java.lang.NoClassDefFoundError:Test
Does this have to do with the classpath? I thought that if your classpath was wrong you wouldn't even be able to compile it in the first place.

Yes, it's related to your CLASSPATH variable which you will need to create in your environment variables. Point it to the subdir where your classes will be after compilation.

PATH is for compiling
CLASSPATH is for running.

On another note, we would appreciate it if you would read http://www.javaranch.com/name.jsp and reregister with a firstName space lastName. We would like you to be able to continue to post here at JavaRanch. Thanks.
[ January 11, 2002: Message edited by: Marilyn deQueiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Chun Wong
Greenhorn

Joined: Jan 11, 2002
Posts: 3
Exception in thread "main" java.lang.NoClassDefFoundError:Test

I don't think that's a "classpath" problem. It happens if your "class name" doesn't match
the "file name". For example, if you
class MyClass
{
....
public static void main(String args[])
{
...
}
}
than you should save the file as "MyClass.java"
as well.
Mike Ottinger
Ranch Hand

Joined: Jan 11, 2002
Posts: 125
Hello I'm formerly mdotting, about what Marilyn said, I didn't realize that path was for compiling and classpath was for executing. I define the classpath as my own variable correct, not a system variable? Sorry I'm new to Windows 2000.


SCJP 1.4 SCJD 1.5
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9052
    
  12
Control Panel
System Properties
Advanced
Environment Variables
You need to add CLASSPATH (probably) to the list of System Variables (not User Variables) and set the Value to what used to be the right hand side of the assignment CLASSPATH = C:\Java; ........
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setting classpath in 2000