Reputation: 83
I have a source file Example.java in the following location:
C:\Users\sushr\Desktop\Experimental Java code\tutorial
Result of dir command from tutorial directory:
Directory of C:\Users\sushr\Desktop\Experimental Java code\tutorial
10/10/2020 01:51 PM <DIR> .
10/10/2020 01:51 PM <DIR> ..
10/10/2020 01:51 PM 133 Example.java <- This is the source file
I am trying to compile this file from location C:\ .
The command that I am running from the command prompt is the following:
C:\>javac -cp "C:\Users\sushr\Desktop\Experimental Java code\tutorial" Example.java
I am getting the following error:
error: file not found: Example.java
Usage: javac <options> <source files>
use --help for a list of possible options
Upvotes: 0
Views: 2082
Reputation: 1
In macOS, I have noticed that using the "~/" to shortcut to home, it does not work. For example:
javac -cp .:~/algs4/algs4.jar MyFile.java
Instead, I had to use the full path to locate the .jar file in order to compile:
javac -cp .:/Users/username/algs4/algs4.jar MyFile.java
Upvotes: 0
Reputation: 19555
The classpath setting for javac
is for finding other libraries and classes while compiling your .java
files. It is not used for finding the .java
files you specified as argument for the javac
program. When you call javac Example.java
and you are currently in the directory C:\
, then it will look for a file C:\Example.java
. It is most likely that the Example.java
file will not be directly in the file system root C:\
.
Either specify the .java
files with an absolute path or adjust your working directory with cd "C:\Users\sushr\Desktop\Experimental Java code\tutorial\"
to go in that directory and compile the files from that location.
Upvotes: 3
Reputation: 354
If you specify the absolute path to your .java file you should be able to just compile it without the -cp flag like so:
C:>javac "C:\Users\sushr\Desktop\Experimental Java code\tutorial\Example.java"
Upvotes: 2