Results 1 to 5 of 5
  1. #1
    Ann22 is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Unhappy classpath - when compiler makes use of that?

    Hi,
    I am learning to set the classpath property. I have a source file say Test.java in the C:\MyLearning\Samples. I have set the environment variable CLASSPATH to C:\MyLearning\Samples. Now am running the Test.java file from the command prompt. The default user directory is shown. Now I tried running the file from there itself giving "javac Test.java".Its not working. But when am pointing to the same direcory where the source is,and then running the program,it works.Why this is so?The concept of classpath is once we set it,we can run the program from anywhere right?If my source is in d: drive,and I want run it from c: drive,is there any other option other than pointing to same direcory of d:?If this is the case,what is the purpose of classpath?am not including any additional jars or anything, but a simple program to run,what else needs to be done?

    Thanks,
    Ann

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    classpath designates the locations of already compiled bytecode. To designate the location of the source code use the -s option. See this.

  3. #3
    Ann22 is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default

    Thank you for your quick reply masijade.

    Why should I do that if I have already set the environment variable 'CLASSPATH'.Once I set the env variable to point to my source,I should be able to run it from anywhere right?Why it is needed to go to the source directory and then run the program?If thats the case,what is the purpose of classpath.Please make it clear for me.

    Thanks,
    Ann

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    What did I say? You want to compile files, which means you need to designate where the source is, right? And what did I say the classpath designates? The location of the already compiled byte code. What is it you do not understand there?

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default

    Also, do not set the environment variable.
    It's a bad habit to get into.
    If you need to set a classpath then use the -cp switch, or something like ant if it's a hefty project.

    Also, when compiling, it's probably an idea to actually compile in the root directory of your project otherwise, as already said, you'll need to set the -s flag as well...which is a bit silly (IMO).

Similar Threads

  1. BufferedReader makes me rage
    By Onra in forum New To Java
    Replies: 3
    Last Post: 10-24-2010, 05:26 PM
  2. System ClassPath and compiler question
    By Moncleared in forum New To Java
    Replies: 1
    Last Post: 02-23-2010, 02:45 AM
  3. Replies: 3
    Last Post: 03-04-2009, 02:56 PM
  4. What makes a good programmer?
    By cruxblack in forum Forum Lobby
    Replies: 35
    Last Post: 11-16-2008, 04:22 AM
  5. Never makes it to the method!
    By minihazard10 in forum New To Java
    Replies: 9
    Last Post: 11-10-2008, 07:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •