Nice tip, thank you oSKAR. This was a problem I was going through too.

shadow_hunt3r.

On 30 jul, 10:41, oSKAR <[email protected]> wrote:
> Hi David:
>
> Go to "Computer" then right click choose "properties" select "Advanced .."
> select "Environment variables" at bottom
>
> then click  "new"
>
> in the fields:
>
> Variable name: CLASSPATH
> Variable Value: %CLASSPATH%;C:\Documents and Settings\Dave\My
> Documents\MyJava
>
> Now you are ready to operate
>
> bye
>
> oSKAR
>
> 2009/7/30 DaveB <[email protected]>
>
>
>
>
>
> > All:
> > Due to help from BlackRookSix and Pacior, the mystery of CLASSPATH is
> > resolved.  I hope that this will help others.
>
> > If there is ANY value in your CLASSPATH variable, you CANNOT use Set
> > CLASSPATH=[new directorypath] by itself.
> > BlackRookSix suggested using echo %CLASSPATH% to obtain the current
> > value.  During the installation of the jdk, you probably had to modify
> > your CLASSPATH variable, so it will contain some value.  The echo
> > command will show it to you.
>
> > To correctly modify this variable, use Set CLASSPATH=%CLASSPATH%;[new
> > directorypath] (Note:  the ";" is for Windows users).  In the example
> > I provided earlier, the complete command is Set CLASSPATH=%CLASSPATH
> > %;c:\tmp
>
> > Now do the command echo %CLASSPATH% and the new directory path has
> > been appended to the CLASSPATH variable and everything works as
> > expected.
>
> > Also, pacior suggested enclosing in quotes.  What I have found is that
> > you only need quotes when there is a literal space in the directory
> > listing.  So for the Windows users, if you were to add something like
> > C:\Documents and Settings\Dave\My Documents, you would have to format
> > it as C:\"Documents and Settings"\Dave\"My Documents"  and everything
> > again will work.
>
> > Thanks to all for pointing in the right direction!
>
> > DaveB
>
> > On Jul 29, 6:56 pm, pacior <[email protected]> wrote:
> > > "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