• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

PATH variable doubt.

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
path variable
I got a doubt with path variable

I had set the path variable like

set path="%path%;c:\jdk\bin;d:\mydir;"

now when I compile the java program from c drive as

c:\>javac d:\mydir\MyProgram.java
There is no problem with compilation.

But if I try without specifying the path
c:\>javac MyProgram.java
I get an error like

error: cannot read: AddTwoNoImpl.java
1 error

Now consider the classpath

I had set the classpath variable like
set classpath="%classpath%;.;d:\mydir;"

now when I execute the java program from c drive as
c:\>java MyProgram

I get the output, because I had included the directory structure of this(MyProgram.class) class file in the classpath variable.

NOTE: we include "c:\jdk\bin" so that we can use the executables like java and javac from any directory without having to specify the full directory structure like
c:\>c:\jdk\bin javac MyProgram.java

Similarly I had included the directory structure of this(MyProgram.java) java file in the path variable. Then why am I NOT able to compile the code without specifying the actual path of the java file.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rama,

Welcome to JavaRanch!

PATH is used by the OS to find programs to run; it's not used by any programs (javac, or any other program) to find documents to operate on. There is no environment variable which tells arbitrary programs to search for documents along a path.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See if this helps with the relationship between path and classpath, source directories and packages, etc.

BTW: My favorite text editor (KEDIT) has searched the path for documents since DOS introduced directories. I published an article in Computer Language magazine about how to do the same in Turbo Pascal. The exception that proves the rule or something like that.
[ January 13, 2006: Message edited by: Stan James ]
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At this point you should only include "c:\jdk\bin" in the PATH variable. You do not need to include the location of your .java files. The typical convention is to change to the directory where your .java files are stored and then run javac and java to compile and run your program. For now, you shouldn't use the CLASSPATH variable. It seems to cause more headache for beginners than it's worth.

Layne
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stan James:
See if this helps with the relationship between path and classpath, source directories and packages, etc.

BTW: My favorite text editor (KEDIT) has searched the path for documents since DOS introduced directories. I published an article in Computer Language magazine about how to do the same in Turbo Pascal. The exception that proves the rule or something like that.

[ January 13, 2006: Message edited by: Stan James ]



Sure, this illustrates that programs CAN do it, but the PATH variable is NOT typically used this way. It is usually a incorrect to assume that they will unless the documentation says otherwise.

Layne
 
Sometimes you feel like a nut. Sometimes you feel like a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic