This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes PATH variable doubt. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "PATH variable doubt." Watch "PATH variable doubt." New topic
Author

PATH variable doubt.

rama murthy
Ranch Hand

Joined: Jan 13, 2006
Posts: 82
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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 ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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
 
Consider Paul's rocket mass heater.
 
subject: PATH variable doubt.
 
Similar Threads
Cannot find symbol error on compile, (and I tried to keep this really simple)
apache tomcat is arrogant...........huh
basic doubt!!
PATH and CLASSPATH
Please help