Spread a lot of configuration run Java articles, did not find the right, including examples, finally patchwork, for everyone to reference:
1. Sublime Text 3--->preference--->Browse Packages, double-click the user folder in the open window. To create a new file Javac.sublime-build, open it with Notepad, paste the following code and save the closing:
{
"cmd": ["javac", "-encoding", "UTF-8", "-d", ".", "$ file"],
"file_regex": "^ (... *?): ([0-9] *):? ([0-9] *)",
"selector": "source.java",
"encoding": "GBK",
// End after executing the above command
// The following commands need to be run by pressing Ctrl + Shift + b
"variants": [{
"name": "Run",
"shell": true,
"cmd": ["start", "cmd", "/ c", "java $ {file_base_name} & echo. & pause"],
// / c is to close the cmd window after executing the command,
// / k is to not close the cmd window after executing the command.
// echo. Equivalent to entering a carriage return
// pause command causes the cmd window to close after pressing any key
"working_dir": "$ {file_path}",
"encoding": "GBK"
}]
}
2. New test file, save as Hello.java:
import java.util.Scanner;
public class Hello {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
System.out.println("输入字符串,exit终止====>");
while (s.hasNextLine()) {
String line = s.nextLine();
if (line.equals("exit"))
break;
System.out.println("out==>"+line);
}
}
}
3, press ctrl+shift+b will pop up an option, such as, select "JavaC" to compile;
Press Ctrl+shift+b to select "JavaC Run".
Operating effect:
Sublime Text 3 Configuration Java Program Runtime Environment (can introduce jar package, console input)