I've recently made the switch to sublime text 2 but I cannot seem to find any plugins/resources which will allow me to implement java console inputs into the editor. I've managed to make it compile and execute java files, but whenever my code needs any input(like a scanner input), the code does not compile and I get an error.
I've seen solutions to make this happen for python, but haven'y managed to find anything on Java.
I was able to figure this out on Windows 8, I haven't tested it on any other platform, hope this works for you.
Install Cygwin [http://www.cygwin.com/]
Make sure the start commands uses the drive:\Path_to_cygwin_installation\bin\start
Create a
javac.sublime.build
systemjavac.bat
; I placed mine under myjava_home
installation.Create your
javac.bat
file and make it available on your environment pathOn my example I had to make sure I kept the application opened:
You can now compile your java files and get it on a new windows.
Okay, I've figured out a complete and perfect solution to this "Run java in Sublime" problem, I've only tested this in Windows 7.
By following the steps below, you will have 2 Build Systems in sublime - "JavaC" and "JavaC_Input".
"JavaC" would let you run code that doesn't require user input and display the results in sublime's terminal simulator, which is convenient and nice-looking.
"JavaC_Input" lets you run code that requires user input in a separate terminal window, it's able to accept user input. You can also run non-input-requiring code in this build system, so if you don't mind the pop-up, you can just stick with this build system and don't switch.
You switch between build systems from Tools -> Build System. And you compile&run code using ctrl+b.
Here are the steps to achieve this:
(note: Make sure you already have the basic setup of the java system: install JDK and set up correct CLASSPATH and PATH, I won't elaborate on this)
"JavaC" build system setup
1, Make a bat file with the following code, and save it under C:\Program Files\Java\jdk*\bin\ to keep everything together. Name the file "javacexec.bat".
2, Then edit C:\Users\your_user_name\AppData\Roaming\Sublime Text 2\Packages\Java\JavaC.sublime-build (if there isn't any, create one), the contents will be
"JavaC_Input" build system setup (mainly the same as @lac_dev 's answer)
1, Install Cygwin [http://www.cygwin.com/]
2, Go to C:\Users\your_user_name\AppData\Roaming\Sublime Text 2\Packages\Java\, then create a file called "JavaC_Input.sublime-build" with the following content
3, Make a bat file with the following code, and save it under C:\Program Files\Java\jdk*\bin\ to keep everything together. Name the file "javacexec_input.bat".
Unfortunately, there are no solutions available for Sublime Text 2 or 3.
But I still love it! So what I usually do is just manually specify the input:
leaving the necessary parts commented for when I need to run the program with input (almost never, in fact).