Sometimes, when you are studying or reading, want to verify a small program in the book or you want to write a simple Java program, and do not want to open the IDE like Eclipse, if you install the sublime text, configure the Java compilation environment, You can compile your Java program directly in it, here are the specific steps:
First you need to download the JDK on your computer, URL https://java.com/zh_CN/, and then add the environment variable (my machine system win10) in the system path, the steps are as follows:
In the path of the environment variable, system--Advanced system settings, Control Panel, all Control Panel items, add the location path of the Java installation to the system variable, which is the following;
Put these basic things in place, then configure your sublime text 3.
Open your Sublime text 3, build your Java build environment in the Tools->build system->new build System with the following code to invoke the CMD command line to achieve the purpose of the interaction, overcoming the sublime Text compilation running Java program console does not make input defects.
The code is as follows:
{
// Commands and parameters, if you don't specify the path, you can find it in the PATH environment variable
"cmd": ["javac", "-encoding", "UTF-8", "-d", ".", "$ file"],
// Optional. Get cmd error output
"file_regex": "^ (... *?): ([0-9] *):? ([0-9] *)",
// Optional. Effective when `Compile` is` Auto` in the `Tools` menu
"selector": "source.java",
// Optional. The encoding of "cmd" is output. Must be a valid Python encoding, the default is "UTF-8"
"encoding": "GBK",
// variants are optional. Used as an alternative to the main build system. If the "selector" of the build system matches the activated file, the variable "name" will appear in the Command Palette.
"variants":
[
{
// Only legal in "variants" (see variants). Used to identify different build systems in the system. If "name" is "Run", it will be displayed under the Tools | Build System menu and can be called using Ctrl + Shift + B
"name": "Run",
// Optional. If the option is "true", "cmd" can be run through the shell.
"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
// The pause command causes the cmd window to close after pressing any key
// Optional. It will switch to this directory before running "cmd" on the first line. After running, it will switch to the original directory.
"working_dir": "$ {file_path}",
"encoding": "GBK"
}
]
// and also:
// line_regex is optional. In the error output of "cmd", file_regex does not match the line. If line_regex exists and does match the current line, the entire buffer is traversed until the line matching file regex appears, and the two matches are used to decide the final The file or line to jump to.
// target is optional. The Sublime Text command to run, the default is "exec" (Packages / Default / exec.py). This command gets the configuration data from .build-system. Used to replace the default build system command. Note that if you wish to override the default commands of the build system, please set them specifically in the .sublime-build file.
// env is optional. Before the environment variables are passed to "cmd", encapsulate them into a dictionary.
// path is optional. This option can replace the PATH of the current process before calling "cmd". The original PATH will be restored after running. Use this option to add directories to the PATH without modifying the system settings.
}
Complete the above steps can be tested in sublime text 3, the following is the result of the test:
Build a Java-compiled environment with sublime text 3