I am very new to JAVA. I have written simple program (in Linux -VIM editor), compiled and executed it, everything is fine.
Now,I have moved that file to a different directory and开发者_JS百科 am trying to compile(javac Myfile.java) it, but it throws an error message as javac-not found
.
Can somebody explain what is the problem?
Your original question was not totally clear (since it did not contain the complete error message).
From your comment:
$ javac Example1.java
javac: file not found: Example1.java
Usage: javac <options> <source files> use -help for a list of possible options
So, javac did not find your file example java.
Normally, you should not have to set the CLASSPATH (use export CLASSPATH=
in bash), and javac would search the source in the current directory. Is your Example1.java
in the current directory? (Type ls
and look at the output.)
If not, you should give the path to this file to javac as a parameter ... but it really is better so simply move to the right directory with cd
.
If you are using packages, position your shell to the directory on top of the package directory hierarchy, and call the compiler with the relative filename from there.
Edit, since I see the next questions coming:
- The compiler will put the resulting class files in the output directory tree given by the
-d
parameter (or the current directory, if not given), by their package structure, so make sure you search them there later (when invoking the program). If the compiler needs other classes to compiler the files indicated in the command line, it searches class files in the classpath (given by the
-classpath
or-cp
option, or by theCLASSPATH
environment variable, or the current directory) and source files in the sourcepath (given by the-sourcepath
option or the classpath if no sourcepath is set). If for a needed both exist and the source file is newer, it is recompiled too. (They are searched according to the package-structure, too.)So in this case you should make sure to pass the
-sourcepath
option so the compiler can find your other source files.
set the classpath and path properly and check whether its working fine.
USAGE:
SET CLASSPATH=%<CLASSPATH>%
SET PATH=%<PATH_WHERE_JDKS_BIN_LOCATED>%
The path environment variable must point to the bin directory in the jdk installation...
USAGE:
Variable : JAVA_HOME
Value : C:\Program Files\Java\jdk1.5.0\bin;.
Variable: PATH
Value : C:\Program Files\Java\jdk1.5.0\lib
System Variables :
Variable : PATH (This will be there already)
Value : %JAVA_HOME%\bin;
Since the file is not in current directory do the below at the prompt
$cd home/kiddosr/Kiddo/Java_Programs/ and press enter
home/kiddosr/Kiddo/Java_Programs at this point of time type javac Example1.java
精彩评论