[Sublime-text] Compiling output Java files with Sublime-text3 under Linux

Source: Internet
Author: User

Because now in the classic books to consolidate some basic knowledge, so will often run some simple procedures, but do not want to open a large IDE. So just want to try to use Sublime-text to compile the program, oh, of course, if used to, with terminal can also. In fact, there is a compile function in the Sublime-text, ctrl+b can be, but only after compiling the. class file, it is not executed, and the results are not visible. For this situation, some configuration file modifications are required. I looked up some methods on the Internet, found that there was no use, I probably groped a bit, found a solution. Of course, this approach is done against JAVA, and of course a slight modification can be used against other languages. Here's how I understand it.

address of this article : http://www.cnblogs.com/rossoneri/p/4378339.html

There is a Packages folder under the Sublime-text folder, which contains many toolkits for various languages. You need to open java.sublime-package for JAVA. Without decompression, open the file Javac.sublime-build directly. CTRL + B compilation is done through this file, you can see the content is:

{"Shell_cmd": "Javac \" $file \ "", "File_regex": "^ (... *):( [0-9]*):? ([0-9]*) "," selector ":" Source.java "}

It is no wonder that only Javac was executed at compile time, so just build the. class file. Now that we need to execute the file to get the result, we need to start with this line of command.

Open the/bin in the JDK directory. Yes, that's the directory where Javac is located, in which we create a new script runjava.sh:

#!/bin/bash[-F"$1.class"] &&RM$1. Class for file inch$1 Do  Echo "-compiling $file. Java ..."Javac $file. Java Doneif[-F"$1.class" ] Then  Echo "------Output------"Java $1Else  Echo " "fi

Remember chmod 777 (OWN environment permissions set to 777 does not matter, not 755, must be executable anyway)

The script means that there is a file Test.java, get its file name test to do parameters, test.class exist to delete it, recompile, compile successfully executed. (Be careful not to delete the blanks)

Then log off the computer, log back in, enter the runjava.sh command in the terminal (in fact, as long as the system can find the file where the line, put the JDK only because the JDK installed after the configuration of its environment, relatively provincial)

After that, modify the Javac.sublime-build file to change the first line to:

" Shell_cmd " " runjava.sh \ "$file _base_name\" ",

Replace the Javac with a new command, followed by the file name, $file on behalf of Test.java, $file _base_name for test, obviously, our command needs the latter as input.

After modifying, save, restart Sublime-text, and let it reload the modified toolkit. Open the file, CTRL + B to see the output.

[Sublime-text] Compiling output Java files with Sublime-text3 under Linux

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.