Compiling from the default directory.

Im trying to compile java programs without having to change the directory in the DOS prompt. By setting up a classpath to my program directory I can run java programs from the base directory using JAVA, but JAVAC refuses to work saying "error cannot read hi.java" there is definitely a hi.java in the same folder as hi.class

Can anyone tell me how to get it to compile without having to change directory? Is there an Environmental Variable to set up?

Thanks for any help.

[490 byte] By [Jumpingmedica] at [2007-10-2 5:12:02]
# 1

The main argument to javac is the path to a source code FILE. This is different from the main argument to java, which is a CLASS name. Classpath is used to find CLASSES. It is not used to find source code FILES.

So for javac, you can do something likejavac c:\path\to\hi.javafrom any directory and javac will find the source code FILE.

The source code may reference another CLASS - if it does, javac will use the Classpath to find the other CLASS.

atmguya at 2007-7-16 1:14:45 > top of Java-index,Developer Tools,Java Compiler...
# 2
You might want to try using JavaTools (see http://fieldbird.com/JavaTools/). It displays the Java commands it executes and the directories in which it executes them in a Log window.
jbiskeborna at 2007-7-16 1:14:45 > top of Java-index,Developer Tools,Java Compiler...
# 3
Thanks for your reply. I know that classpath tells it where to find classes. I just wanted to know if theres a way of telling java where to find the .java files.It's just a pain having to point to the directory where the .java file is everytime i want to compile a program.
Jumpingmedica at 2007-7-16 1:14:45 > top of Java-index,Developer Tools,Java Compiler...
# 4
You can write a wrapper script to avoid the painful directory changing with every compilation.
BIJ001a at 2007-7-16 1:14:45 > top of Java-index,Developer Tools,Java Compiler...