Write and run java program using Sublime Text 2
Sublime Text 2 is one of my Favorite text editor for coding after Geany. This is an awesome and light weight editor. What I loved to share is how to setting ST2 then you can use it to compile and run java programs directly.
Follow these steps below to prove it 🙂
- Firstly, make sure that you already have jdk installed. Or you can download here.
- After installing then set the PATH variable on Environment Variables (Right click on My Computer > Properties > Advanced system settings > Environment Variables).
- Then go to System variables > Path > add jdk bin directory path. On my laptop is C:\Program Files\Java\jdk1.7.0_17\bin
- Create a bash shell script file runJava.bat :
- Next step is setting this bash shell script in the build system of ST2. Open ST2 > Preferences > Browse Packages > go to Java Folder > Open JavaC.sublime-build and replace this line “cmd”: [“javac”, “$file”], with this “cmd”: [“runJava.bat”, “$file”], then save.
- Done. Then open your java program using ST2 or write a simple program and click Tools > Build or simplify you can press Ctrl+B.