Running Java programs
I have a Pentium 3 PC with 512 MB ram. I installed Jdk 1.4 and have set the path to point to lib and bin.
I am able to successfully execute javac, java commands.
however, when i try to run a java application, it says 'ClassDefNotFoundException'.
I could resolve this error by giving the path in which the .class resides in the classpath variable.
Does this mean tht if i change my working directroy, i need to modify my classpath to reflect the same.
Is there any work around to this problem?
regards,
J
I'm not sure if this involves a workaround, it is how the language is designed. At runtime, the JVM needs to know where to locate the classes to load during execution. Now, if you are in a given working directory, it will implicitly assume that is part of the classpath when you launch java.
Let's take the other tact: specify the runtime location in the classpath and put the java command into a script or bat file. Now, you should be able to execute the script from anywhere else on the filesystem, and the JVM will still locate the classes because you have explicitly defined where they reside.
Basically, and this is not the exactly correct term, but the classpath is Java's linking mechanism. It needs to know where to find the classes to load.
- Saish
"My karma ran over your dogma." - Anon
Saish at 2007-7-1 21:42:12 >

You can add "." to the classpath, which means the current directory. Then, no matter where you are, Java will also look in the current directory if it can't find a class elsewhere. For example, my classpath reads ".;c:\matei\java" since I have some classes in c:\matei\java but also in other places where I just want to use the current directory.
By the way, in case you didn't know, you can also set the classpath as an environment variable rather than setting it in DOS each time by using Control Panel > System > Advanced > Environment Variables and adding it to System Variables.
Matei at 2007-7-1 21:42:12 >

i was this question and solve in shape:
first you set classpath in prompet that points to path of folder classes before run application .
in this way :
for example is in e:\
e:\ set classpath=<path of folder classes> ENTER
e:\ java<name of application without .class>