• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setting classpath in 2000

 
mdotting
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Chun Wong
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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; ........
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic