Reputation: 1406
I am experimenting with the javac
command line options, in order to learn about the -sourcepath
and -classpath
options. When I run javac
, having tried four different command line options for it, I am unable to obtain a recompiled .class file.
Here is my folder structure. Please note that due to testing, the Test.java file is located inside the "bat" folder, which is an admittedly odd location.
projects \ prj1 \ bat \ bat.bat
Test.java
Test.class <--- unable to obtain recompiled file.
src \ Main.java
Main.class
The contents of my two .java test files are:
// Main.java, located in the src folder
class Main {
public static void main(String[] args) {
new Test();
}
}
// Test.java, located in the bat folder
class Test {}
Regarding the execution of javac
at the command prompt, here are four options that I have tried. I've run these commands from a batch file called bat.bat, which is located inside the "bat" folder.
javac ..\src\Main.java (no sourcepath, no cp)
javac -sourcepath . ..\src\Main.java (sourcepath)
javac -cp . ..\src\Main.java (cp)
javac -sourcepath . -cp . ..\src\Main.java (sourcepath, cp)
In all of these javac
commands above, I am unable to obtain a recompiled .class file, for the Test.java file. Is this because I have not edited the Test.java file, since initially compiling it? Please note that I have no CLASSPATH
environment variable set. Thanks.
Upvotes: 3
Views: 201
Reputation: 417682
If class files are already present in the destination / output folder, javac
will only recompile the source java file if it has been modified since the date/time of the class file.
If you want to recompile the source files, then first delete the *.class files before calling javac
.
Upvotes: 3