Compiling and running Java programs in Sublime Text 2

Source: Internet
Author: User
Tags sublime text
Click on the "Preferences" menu, select "Browse Packages" to open the directory of the plugin, find the "Java" Item, double-click Open. A file with a suffix named Sublime-build is a command to compile the program, find Javac.sublime-build, and drag into sublime Text 2 to open for editing. Here is my own Java program compile and run files, if you have installed the JDK and configured the environment variables, you can copy and paste directly. {
"cmd": ["Javac", "-encoding", "UTF-8", "$file"],
"File_regex": "^ (... *?):( [0-9]*]:? ([0-9]*) ",
"Selector": "Source.java",
"Encoding": "GBK",

"Variants":
[
{
"Name": "Run",
"cmd": ["Java", "$file _base_name"],
"Encoding": "GBK"
}
]
}

"cmd" represents the command to execute, [] is the command to execute, can be parameters, parameters can not have spaces, the contents of each pair of quotes will be automatically quoted. such as "Javac", "-encoding", "UTF-8" will be executed as "javac-encoding UTF-8", "$file" represents the file name of the current file, with the suffix name. The next two lines do not need to be adjusted. The last line, "encoding": "GBK", indicates that sublime text 2 communicates with the system using GBK encoding. Because the sublime text 2 only supports UTF-8 encoding, because the Java file written with it is UTF-8 encoding, the encoding format supported by the Windows Chinese version is GBK, if it is in English, the two encoding formats are generally not midway, but when Chinese is present, The two are not fully compatible, so if an error message occurs, whether it is a syntax error or a coding problem, sublime text 2 will not display an error message. So compile to add-encoding UTF-8 parameters, and get system Information, add "encoding": "GBK", so that Javac compiled to know the source program is UTF-8 information, and the system execution or compile the file feedback information back to the sublime Text 2 o'clock, sublime text 2 also know to get the GBK encoded information, there will be no error. "Variants":
[
{
"Name": "Run",
"cmd": ["Java", "$file _base_name"],
"Encoding": "GBK"
}
This section represents the settings for running the program, and "$file _base_name" represents the filename, but does not contain a suffix name.
"Java", "$file _base_name" means using a Java command to execute a program, because there is no suffix name, so use "$file _base_name", "Encoding": "GBK", as described above.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.