Sublime Text 2 build system to compile & run Java in a new Terminal/Command Prompt window?

后端 未结 3 1698
甜味超标
甜味超标 2020-12-16 23:28

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

3条回答
  •  悲&欢浪女
    2020-12-17 00:07

    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.

提交回复
热议问题