-
Running Java Compiler
I am new to Java and I was wondering how I can compile a file with my javac compiler without having the file in the directory. Now I am compiling my java by having putting my files.java into the bin directory in which my javac compiler is in. I would like to compile my files from any directory with my javac compiler. How do i go about doing this.
Help is appreciated.
Please provide code if possible.
-
It is not necessary that you put your .java files in the bin directory. You can place your files in any directory that you choose as long as you specify the directory where the file is located that you wish to compile. ie... C:\jdk1.3\bin javac C:\Java\MyFile.java
Now to compile you have to be in the bin directory unless you change that so you can compile your .java files from outside of that directory.
From the DOS command line type set. A whole bunch of stuff should be listed. The second to last entry should read path = Now at the command line type in path = C:\jdk1.3\bin. Now when you go back by typing set you should see that the path will now say C:\jdk1.3\bin. This enables you to compile with out having to be in the bin directory.
As for being able to run files i dont think that the class path can be set from dos itself. The usual method is to set the CLASSPATH environment variable to point to the directory where the .class files reside that you want to run. But remember that once you change the autoexec.bat file a system reboot is needed for the changes to take effect. You can always run using C:\jdk1.3\bin -classpath C:\MyPath; MyProgram
-
You need to modify the environment variable PATH.
Depending on your OS you may be able to do this with AUTOEXEC.BAT. If not, you will need to go into System Properties. I'm not familiar with all the flavors of Windows, but in Win2K, right-click My Computer and select Proberties. Select the Advanced tab and click Environmental Variables. Scroll down the System variables list, select Path and click Edit. In NT (if I remember correctly) you have to go into Environment in the Control Panel
To make the change to Path, you simply need to add the path to your javac compiler. For example, if you have a basic path variable, it will look something like this:
C:\WINNT\system32
All you will need to do is add the location of javac.exe to the list so it looks like this:
C:\WINNT\system32;c:\jdk1.3\bin