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