classpath help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeffbroodwar
    New Member
    • Oct 2006
    • 118

    classpath help

    Hi All,

    I'm trying to run a sample program from this link:

    http://java.about.com/od/tutorials/ss/SetClasspath.ht m

    it worked fine.. now the problem is... what if i do not want to use the set classpath command, instead, i just want to set the classpath in my system environment variable so that everytime i run the program, i'll just type javac file then java file. I tried to set this in the environment variable :

    variable name: classpath
    variable values: c:\javatest

    but its not working... can anyone help me with this?

    Thanks,
    Pupoy
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Can you show us what you originally set using the -classpath flag? For the
    environment version everything is similar: as a flag:

    -classpath=foo

    and as an environment variable:

    set classpath=foo

    kind regards,

    Jos

    Comment

    • jeffbroodwar
      New Member
      • Oct 2006
      • 118

      #3
      Hi Jos,


      Thanks for the reply... i tried to type this in the command line :

      STEP1 : set PATH = c:\program files\Java\jdk1 .6.0_03\bin

      STEP2 : javac C:\javatest\Bar kingDogs.java

      (Then specify where to find the class)

      STEP3 : java -cp c:\javatest BarkingDogs

      after completing these steps... i had a successful ran of the snippet...

      Now, correct me if i'm wrong...is it correct that i can run the program by just typing :
      * (for compiling)
      javac BarkingDogs.jav a

      * (for running program)
      java BarkingDogs

      meaning running the program by just doing steps 2 and 3(without cp word in step 3) since class path is already in environment variable.

      Back to the original question... i just added under system environment variables :

      variable name: classpath
      variable value: ?

      i'm using windows xp

      Thanks,
      Pupoy

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Your reasoning is all sound and solid but you have to pay special attention to
        those path names with spaces in them. You need to use double quotes around
        them otherwise MS Windows starts to be creative which you don't want.

        kind regards,

        Jos

        Comment

        • jeffbroodwar
          New Member
          • Oct 2006
          • 118

          #5
          i dont get the spaces... u mean in the classpath values?

          by the way, can you please give me a working class path for windows... just to accomplish the 2 steps i mentioned in my previous post:

          javac BarkingDogs.jav a

          java BarkingDogs

          and... do i really always have to tell the windows where the java compiler is(Set path command) ? can't i just include it in the class path? separated by ;


          Thanks,
          Pupoy

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            There are a few separate issues that have not much to do with each other:

            The PATH variable
            The PATH variable is a semi colon separated list of directories. The OS searches
            those directories for executable files for which no explicit complete path was
            given. java.exe and javac.exe are examples of executable files.

            The CLASSPATH variable
            The CLASSPATH variable is a semi colon separated list of directories and .jar
            files. The JVM searches them for classes.

            So you have to set your PATH variable to a suitable value if you just want to be
            able to type 'java' or 'javac'. You have to set your CLASSPATH to the directories
            where your .class files are stored and to the complete names of your .jar files.

            If you want to be able to type 'javac MyClass.java' you have to change your
            current working directory to where your MyClass.java file is stored.

            btw. the space character I mentioned is present in the 'Program Files' directory
            name. You have to take care of it by using double quotes. Check your manuals.

            kind regards,

            Jos

            Comment

            • jeffbroodwar
              New Member
              • Oct 2006
              • 118

              #7
              Hi,

              I know what executable files are... LOLZ.

              btw, its just that i'm not really familiar on how to set the windows environment variable configuration. that's all. ROTFL...

              thanks Jos, ^^ ;

              Kind regards,
              Pupoy

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by jeffbroodwar
                Hi,

                I know what executable files are... LOLZ.

                btw, its just that i'm not really familiar on how to set the windows environment variable configuration. that's all. ROTFL...

                thanks Jos, ^^ ;

                Kind regards,
                Pupoy
                Check your Windows manuals for that issue, it has nothing to do with Java.

                kind regards,

                Jos

                Comment

                • jeffbroodwar
                  New Member
                  • Oct 2006
                  • 118

                  #9
                  I tried to create a new variable in the environment variables of windows...

                  variable : CLASSPATH
                  value : c:\javatest

                  still, i can't make it run in root directory :

                  c:\>javac BarkingDogs.jav a
                  c:\>java BarkingDogs

                  once classpath is defined in environment variable.... the system should already know the class location right? using java and javac keywords should trigger the variable classpath and tell the computer to get the value of the classpath variable...why is it still not working?

                  Thanks again,
                  Pupoy

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    Originally posted by jeffbroodwar
                    I tried to create a new variable in the environment variables of windows...

                    variable : CLASSPATH
                    value : c:\javatest

                    still, i can't make it run in root directory :

                    c:\>javac BarkingDogs.jav a
                    c:\>java BarkingDogs

                    once classpath is defined in environment variable.... the system should already know the class location right? using java and javac keywords should trigger the variable classpath and tell the computer to get the value of the classpath variable...why is it still not working?

                    Thanks again,
                    Pupoy
                    You can't compile a file BarkingDogs.jav a when your current working directory
                    is not the directory where that file is stored.

                    kind regards,

                    Jos

                    Comment

                    • jeffbroodwar
                      New Member
                      • Oct 2006
                      • 118

                      #11
                      hmm.... I tried to add classpath variable in the user variables (the one at the top)
                      , it worked for running the class file. but when i try to compile .java files... it can't locate the directory of classpath.

                      c:\>javac BarkingDogs.jav a = (Doesn't work)

                      (lets say the directory contains class files)

                      c:\>java BarkingDogs = (successful !)

                      here's my classpath variable :

                      variable : classpath
                      variable value : .;c:\javatest


                      It seems that the system can now see the classpath variable when using java command. but if i'll try to use javac command.... hmm... not working?! that's weired ! (FYI : i already added in system variable the path of java compiler
                      i.e. c:\program files\Java\jdk1 .6.0_03\bin

                      Thanks again,
                      Pupoy

                      Comment

                      • jeffbroodwar
                        New Member
                        • Oct 2006
                        • 118

                        #12
                        just received your reply jos. thanks. so it's not possible to use javac command in any directory even if you've set the classpath variable. only java command to execute the file will work. now i understand. thanks man.

                        Thread closed.

                        Thanks,
                        Pupoy

                        Comment

                        Working...