Run Java code directly with Sublime Text 2 under MAC system

Source: Internet
Author: User
Tags sublime text



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


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.