I would like to make a build system in Sublime Text 2 that will compile a Java file, and then run it in a new Terminal (for OS X or Linux) or Command Prompt
I didn't have to use all these long methods. Well not for big projects. An example build system is
{
"cmd": ["javac '$realpath$file' && java $file_base_name && rm *.class"],
"selector": "source.java",
"shell": true,
"variants": [
{
"name": "JavaDoc",
"cmd": ["mkdir documentation && javadoc -d documentation *.java"]
},
{
"name": "JAR",
"cmd": ["javac '$realpath$file' && echo \"Main-Class: $file_base_name\" > Manifest.txt && jar cfm $file_base_name.jar Manifest.txt *.class && rm *.class && java -jar $file_base_name.jar"]
},
]
}
This works for me on Linux and can be downloaded on Github at Java,sublime-build
The interesting thing is that it also compile files to JAR. Remove classes after compilation to make things neater and it also support generating JavaDocs.
The only limitation is that it cannot accept user input or arguments at compile time. You would have to do that manually in the terminal.