Ubuntu under Sublime Text 3 Configuring the basic Java Environment

Source: Internet
Author: User
Tags sublime text

Step #1. Set the Java PATH variable

This is the first and most basic step to set up a store path for compiling and running Java Program basic commands such as Javac and Java.
1. Enter/etc directory in the console
2. Open the Environment file with Administrator privileges:
sudo gedit /etc/environment
3. Paste the JDK Bin directory to the end of the path variable and save the file to exit the editor
4. Log out and log back in

Step #2. Create a batch or shell script

To compile and run a Java program, you need to create a batch or shell script
Create a file using the following code runjava.sh
[ -f "$1.class" ] && rm $1.class
for file in $1.java
do
echo "Compiling $file........"
javac $file
done
if [ -f "$1.class" ]
then
echo "-----------OUTPUT-----------"
java $1
else
echo " "
fi

→note: If you want to compile all the Java files, you need to replace the $1.java in the second row with the *.java

Use the following command to move the script file to the bin directory of the JDK
Sudo mv runJava.sh /usr/lib/jvm/jdk1.6.0_17/bin

To set the executable permission of the file after the move is 755 to ensure that the file is executable, under Ubuntu you can select the executable option on the tab of permissions by right-clicking the property.

Step #3. Modify Javac.sublime-build

Follow the steps below to modify the compiled system script for sublime text 3.

Locate the% installation directory%/package/java.sublime-package, open with good pressure or other compression software, find javac.sublime-build in it, size is 1kb

Then open the file with a text editor and modify it to
{
"shell_cmd": "runJava.sh \"$file_base_name\"",
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.java",
  //添加下面一段可支持编译中文,亲测Java可用
   "encoding": "GBK"
}

Step #4 – now write a test program and use Ctrl+b to try it out!

public class Hello{
public static void main(String[] args) {
System.out.println("Hello Sublime Text 3!");
}
}

Ubuntu under Sublime Text 3 Configuring the basic Java Environment

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.