Configuring Sublime Text 2 editor to compile and run Java programs
- Details
- Written by Nam Ha Minh
- Last Updated on 02 July 2019   |   Print Email
[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 )
[ -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!"); } }
Related Java Editors / IDEs Tutorials:
- How to compile and run a Java program with Sublime Text 3
- How to Compile and Run a Java Program with TextPad
- How to use Eclipse IDE for Java EE Developers
- How to Use NetBeans IDE from the Basics
Other Java Coding Tutorials:
- 10 Common Mistakes Every Beginner Java Programmer Makes
- 10 Java Core Best Practices Every Java Programmer Should Know
- How to become a good programmer? 13 tasks you should practice now
Comments
C:\Program Files\Sublime Text 3\Packages
The Java package is called "Java.sublime-package".
These ".sublime-package" files are actuallu just .ZIP files with a different extension. I used my ZIP package viewer, 7ZIP, to open the archive and gain access to the JavaC.sublime-build file so you can add the runJava.bat statement.