[Error 2] The system cannot find the file specified
Once you corrected the PATH variable, you may need to restart the editor to take effect. Then press Ctrl + B again, you would see the successful message like this:
To run the compiled class, you need to do some extra steps (on Windows): 1. Create a batch script file called runJava.bat with the following content:@ECHO OFF cd %~dp1 ECHO Compiling %~nx1....... IF EXIST %~n1.class ( DEL %~n1.class ) javac %~nx1 IF EXIST %~n1.class ( ECHO -----------OUTPUT----------- java %~n1 )
Replace the text “javac” by “runJava.bat”:
Then press Ctrl + B again, you would see the following result:
NOTE: If you are on a Linux system, create the following shell script file:[ -f "$1.class" ] && rm $1.class for file in $1.java do echo "Compiling $file........" javac $file done if [ -f "$1.class" ] then echo "-----------OUTPUT-----------" java $1 else echo " " fiSave this file as runJava.sh under JDK’s bin folder, and update the JavaC.sublime-build file by replacing “javac” by “runJava.sh”.Here's the Java source file:
public class HelloJava {
public static void main(String[] args) {
System.out.println("Hello Java!");
}
}
Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.