• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PATH variable doubt.

 
rama murthy
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • 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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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 ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic