1

when I choose c++ in Bulid System , I notice there is "Run" command below. However, when I choose JavaC in Build System , The "Run" label is missing. how can I add this label to compile and run java ? what's more, among the answers in Compiling and Running Java Code in Sublime Text 2 , I prefer @vijay's than any other ones, but when I config the following code as he suggested, It does not work when I type "shift+ctrl+b" to run java program

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

"variants": [

    { "cmd": ["java", "$file_base_name"],
      "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
      "selector": "source.java",
      "name": "Run Java"
    }
]
}
Community
  • 1
  • 1
user861491
  • 149
  • 1
  • 11

1 Answers1

2

Sublime Text 2 will only offer a Run menu item (with shortcut Ctrl+Shift+B) if there is a build system variant with the name Run (see name documentation here). In your build system, change this:

"name": "Run Java"

to this:

"name": "Run"

Afterwards, Ctrl+Shift+B should execute the java command that you're going for.

Any other variants that you add will appear in the Command Palette (Ctrl+Shift+P) with a name like Build: Foo but will not be assigned a keyboard shortcut. The one named Run will always be mapped to Ctrl+Shift+B no matter what order the variants are in.

angerson
  • 7,342
  • 1
  • 21
  • 24