This article refers to a lot of articles on the Internet, it is not listed.
The version of Sublime is sublime test 2
JDK version jdk1.7
1. The Mac appears to be able to run Javac and Java commands directly, if not directly run, you can add the Java environment variable
2. After installing sublime Text 2, enter the following folder
2/packages/java
3. Back up the Javac.sublime-build file
CP Javac.sublime-build Javac.sublime-build.back
4. Open the Javac.sublime-build file and modify the content
$ vi JavaC.sublime-build
Amended as follows:
{
"cmd": ["javac \" $ file \ "&& java \" $ file_base_name \ ""],
"shell": true,
"file_regex": "^ (... *?): ([0-9] *):? ([0-9] *)",
"selector": "source.java"
}
5. Save Javac.sublime-build File
6. Write the Java file in sublime, command+b run it
When searching online, you will encounter some tutorials that use runjava.sh to run. Here too.
1. In the Java Bin directory. I'm here to add files under/usr/bin runjava.sh
2. Add the following content to the file
$ cat runJava.sh
[ -f "$1.class" ] && rm $1.class
for file in *.java
do
echo "Compiling $file........"
javac $file
done
if [ -f "$1.class" ]
then
echo "-----------OUTPUT-----------"
java $1
else
echo " "
fi
3. Save and modify the runjava.sh format to the following format
ls -l | grep Runjava. sh-rwxr-xr-x 1 root wheel 235 9 423 : Runjava. SH
Instruction for chmod 755 runjava.sh
4. Open the Javac.sublime-build file and modify the content
cat JavaC.sublime-build
{
"cmd": ["runJava.sh \"$file_base_name\""],
"shell":true,
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.java"
}
5. Save Javac.sublime-build File
6. Write the Java file in sublime, command+b run it
Run Java code directly with Sublime Text 2 under MAC system