From the following directory:
C:\Program Files\Java
I can compile my
Java program using either of the following two commands:
javac "C:\Program Files\Java\jdk1.6.0_21\bin\HelloRanch.java"
javac "jdk1.6.0_21\bin\HelloRanch.java"
However, despite the fact that the program runs... which I can accomplish while in the same directory, typing:
java HelloRanch
I am not able to run the program if I try to explicitly name the full path and filename, such as:
java "C:\Program Files\Java\jdk1.6.0_21\bin\HelloRanch"
java "jdk1.6.0_21\bin\HelloRanch"
using either of these, and I will get an error:
Exception in thread "main" java.lang.NoClassDefFoundError: C:\Program Files\Java\jdk1/6/0_21\bin\HelloRanch
Caused by: java.lang.ClassNotFoundException: C:\Program Files\Java\jdk1.6.0_21\bin\HelloRanch
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: C:\Program Files\Java\jdk1.6.0_21\bin\HelloRanch. Program will exit.
Because I couldn't be sure if part of the problem was the way the jdk directory was displayed on the first line of the error ("\jdk1/6/0_21"),
I moved to the directory:
C:\Program Files\Java\jdk1.6.0_21
and then typed:
java "\bin\HelloRanch"
... but I also received essentially the same error.
Is there a way to execute a java program using the full directory name? If it's part of the java command options, I missed it.
Any help that could be given would be greatly appreciated.