Run java file from Sublime Text 2

After download java SDK, we need to configure javaC.sublime-build (Sublime Text 2 -> Preferences -> Browse Packages).
Github has gist just for it:

{
 "cmd": ["javac", "$file_name"],
 "cmd": ["java", "$file_base_name"],
 "working_dir": "${project_path:${folder}}",
 "selector": "source.java"
 }

or

{
 "cmd": ["javac", "$file_name", "&&", "java", "$file_base_name"],
 ...
 }

But since cmd takes only one argument, this cases should be appended by shell scripts  of different complexity for parsing multiple arguments. To avoid this, we change the first line and add a line which make us treat all commands as shell instructions:

{
"cmd": ["javac $file_name && java $file_base_name"],
"working_dir": "${project_path:${folder}}",
"selector": "source.java",
"shell": true
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s