Compiling and running Java programs on Sublime Text 3 (pro-test pass)

Source: Internet
Author: User
Tags sublime text

At present, a lot of articles on the Internet in sublime Text 2 to build a Java development environment, this article describes the Windows system in sublime text 3 on how to build a Java development environment, the two a little different.



1. Set Java Path variable settings to compile and run Java Program basic commands (such as Javac and Java) storage path.
Step: Right Button "My Computer" select "Properties" to go to advanced system settings find and click the "Environment variables" button to enter the system variable and find the path variable paste the JDK's Bin directory to the PATH variable value last (you can enter echo%PATH% in cmd to view the PATH variable settings Whether successful)

2. Create Batch script Runjava.bat to compile a Java program, you need to create a batch script.

New file Runjava.bat, file content is

@ECHO off
cd%~dp1
ECHO compiling%~nx1
.... If EXIST%~n1.class (
DEL%~n1.class
)
javac%~nx1
if EXIST%~n1.class (
ECHO----------- OUTPUT-----------
java%~n1
)


3. Place the Runjava.bat into the JDK Bin directory and place the Runjava.bat in the bin directory of the previously configured JDK, which is called Runjava.bat in the Javac.sublime-build later.

4. Modify Java.sublime-build original Javac.sublime-build, will only generate a. class file, you need to make the appropriate changes in order to compile and get results.
In sublime text 3, the "javac.sublime-build" file is stored in the (c| d| e|*): \program Files\sublime Text3\packages Directory in the Java.sublime-package package file.



You can use compressed software such as good compression to open the form of compressed files, you can find that there is a javac.sublime-build file in the java.sublime-package.


Replace the contents of the file with the following:

{
	"cmd": ["Runjava.bat", "$file"],
	"File_regex": "^ (... *?):( [0-9]*]:? ([0-9]*) ",
	" selector ":" Source.java ",
	" encoding ":" GBK "
}


Note: This is used for the Runjava.bat batch file that was previously edited.
5. Write the test program new Test.java file, the contents of the file is

public class test{public
	static void Main (string[] args) {
		System.out.println ("Hello world!");
		int a = ten;
		int b =;
		int C = a + B;
		SYSTEM.OUT.PRINTLN ("Result:" + C);
	}
}


6. TestTest results are:




Reference1. Compiling and running Java programs in Sublime Text 2 http://www.oschina.net/translate/compile-and-run-java-programs-in-sublime-text-2?cmp
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.