Skip to content

Instantly share code, notes, and snippets.

@mickeypash
Created January 26, 2015 20:02
Show Gist options
  • Save mickeypash/ee1fd034733e8e46785b to your computer and use it in GitHub Desktop.
Save mickeypash/ee1fd034733e8e46785b to your computer and use it in GitHub Desktop.
Run and Compile Java from SublimeText 2
{
"cmd": ["javac", "-Xlint", "$file"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.java",
"variants": [
{ "cmd": ["javac", "-Xlint", "$file"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.java",
"name": "Java Lintter"
},
{ "cmd": ["java", "$file_base_name"],
"name": "Run Java"
}
]
}
@mickeypash
Copy link
Author

What this does is that it creates variants to the regular build command (ctrl+b). With ctrl+b you will still be able to compile your code. If you do shift+ctrl+b the first variant will be executed, which in this case is javac with the -Xlint option. The second and final variant is the java command itself. you can place this as your first variant and shift+ctrl+b will actually execute the java code.

Also, notice that each variant as a "name". This basically allows this specific "build" option to show up in the shift+ctrl+p option. So using this configuration, you can simply do shift+ctrl+p and type "Run Java" and hit enter, and your code will execute.

Thanks to @vijay

  • to use ctrl+shift+b to run, change "name" field to "Run"
  • This has Changed for ST3: * replace "cmd" with shell_cmd * remove the squre braces * put the whole command in a string

@mickeypash
Copy link
Author

The original:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment