"4.  I set the CLASSPATH (C:\tmp>set CLASSPATH = c:\tmp) then change
to the parent directory which does not contain the class file."
It fails, beacuse of white spaces.
try:
set CLASSPATH="c:\tmp"

Pacior

On Jul 29, 9:39 pm, David Banish <[email protected]> wrote:
> All:
> I am in Lesson 3, Packages and Java Classpath.
> I thought I got the Classpath, but now I am not so sure.
>
> In the Command Line Stream below, I have the Hello.class in 2 
> directories(...MyJava and C:\tmp).
> 1. The first command (C:\Documents
> and Settings\Dave>java Hello) is expected to fail because the class is not in 
> the current directory.
> 2. I change directories to one that contains the class file and execute again 
> (C:\Documents
> and Settings\Dave\My Documents\MyJava>java Hello) successfully because the 
> class is located in that current directory.
> 3. I change directories again to the second directory that contains a copy of 
> the class file and successfully execute (C:\tmp>java
> Hello)
> 4.  I set the CLASSPATH (C:\tmp>set
> CLASSPATH = c:\tmp) then change to the parent directory which does not 
> contain the class file.
> 5. At this point, I would expect the class file to execute because of the 
> CLASSPATH being set, but it does not
>
> C:\>java
> HelloException in thread "main"
> java.lang.NoClassDefFoundError: Hello
> 6.  I display the classpath which seems correct
>
> C:\>set
> classpath
> CLASSPATH=.;C:\Program
> Files\Java\jre6\lib\ext\QTJava.zipCLASSPATH
> = c:\tmp
> 7. But, if I use the -classpath option in the java line, it works as expected 
> (C:\>java
> -classpath c:\tmp Hello)
>
> So
> can anyone help me as to why the Classpath does not seem to work as
> expected?  I did notice that my "set Classpath" statement created a
> second line with classpath listed twice.  Is that it?
>
> ------
>
> C:\Documents
> and Settings\Dave>java Hello
> Exception in thread "main"
> java.lang.NoClassDefFoundError: Hello
> Caused by: java.lang.ClassNotFoundException:
> Hello
>         at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at
> java.net.URLClassLoader.findClass(URLClassLoader.java:188)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
>         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
>         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
> Could not find the main class: Hello.  Program will exit.
>
> C:\Documents and Settings\Dave>cd My
> Documents\MyJava
>
> C:\Documents
> and Settings\Dave\My Documents\MyJava>java Hello
> Hello world
>
> C:\Documents and Settings\Dave\My
> Documents\MyJava>cd c:\tmp
>
> C:\tmp>java
> Hello
> Hello world
>
> C:\tmp>set
> CLASSPATH = c:\tmp
>
> C:\tmp>cd c:\
>
> C:\>java
> Hello
> Exception in thread "main"
> java.lang.NoClassDefFoundError: Hello
> Caused by: java.lang.ClassNotFoundException:
> Hello
>         at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
>         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
>         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
> Could not find the main class: Hello.  Program will exit.
>
> C:\>set
> classpath
> CLASSPATH=.;C:\Program
> Files\Java\jre6\lib\ext\QTJava.zip
> CLASSPATH
> = c:\tmp
>
> C:\>java
> -classpath c:\tmp Hello
> Hello world
>
> Thx to all,
> DaveB

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to