• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

setting classpath in 2000

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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; ........
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic