简体   繁体   中英

Sublime text 3 how to: Java output

Recently I have discovered Sublime Text 3, but when I try to run Java with for example some println's it doesn't return anything. All it does is say "[Finished in x seconds]". Can someone please explain how to make it output text when I run my code. I am on mac os 10.9.5

Code example:

public class Main{
    public static void main(String[] args){
        System.out.println("Hello, world!");
    }
}

That's because you are not running anything. The default java plug-in won't run code until you modify it. You are only building (compiling) your code.

To modify the plug-in you have to go to /Packages and unzip the Java.sublime-package file:

cd <sublime-text3-folder>/Packages
mkdir java
cp Java.sublime-packages java
cd java
unzip Java.sublime-packages

Then use an editor (vi, emacs...) and modify JavaC.sublime-build to add the following lines (don' forget the extra comma after the last line

{
   "shell_cmd": "javac \"$file\"",
   "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
   "selector": "source.java",

   "variants":
   [
       {
            "name": "Run",
            "shell_cmd": "java $file_base_name"
       }
   ]
}

Zip again the contents in Java.sublime-package and put it back in Package folder via:

zip Java.sublime-package *
cp Java.sublime-package ../<sublime-text3-folder>/Packages

Restart sublime and now along with Ctrl+B to build your project you will be able to run it with Ctrl + Mayus + B

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM