I'm trying to run java and javac from the command line, but I'm having trouble setting the CLASSPATH for the javac sdk tool.
I've successfully added the CLASSPATH variable through the windows environmental variable settings, and this works for the java command. I am able to execute class files from any directory in the command line. However, when trying to use the javac command (where the .java files are in the same CLASSPATH directory), i receive the error message that the file is not found.
My CLASSPATH variable is set to:
C:\Users\ejovo\OneDrive\Documents\Coding\Java>
Here are 3 examples of what I mean.
C:\>javac MyFirstApp.java
javac: file not found: MyFirstApp.java
Usage: javac <options> <source files>
use -help for a list of possible options
C:\Users\ejovo\OneDrive\Documents\Coding\Java>javac MyFirstApp.java
C:\>java MyFirstApp
Hello World
We see that the java command can be run from anywhere while the javac still has to be run from the directory in which the .java files are.
I've tried setting the javac CLASSPATH with the -cp and -classpath options without any luck:
C:\>javac -cp C:\Users\ejovo\OneDrive\Documents\Coding\Java
javac: no source files
Usage: javac <options> <source files>
use -help for a list of possible options
C:\>javac -classpath C:\Users\ejovo\OneDrive\Documents\Coding\Java
javac: no source files
Usage: javac <options> <source files>
use -help for a list of possible options
And I've already set a PATH variable that makes the java and javac commands run correctly
I've also tried changing the sourcepath with the -sourcepath argument:
C:\>javac -sourcepath C:\Users\ejovo\OneDrive\Documents\Coding\Java
javac: no source files
Usage: javac <options> <source files>
use -help for a list of possible options
Despite that, I clearly do have a .java source file present:
Directory of C:\Users\ejovo\OneDrive\Documents\Coding\Java
07/25/2019 03:08 PM <DIR> .
07/25/2019 03:08 PM <DIR> ..
07/25/2019 03:29 PM 425 MyFirstApp.class
07/24/2019 06:40 PM 127 MyFirstApp.java
2 File(s) 552 bytes
2 Dir(s) 57,735,630,848 bytes free
Let me know if anyone has any other ideas!