在 Sublime Text 2 中编译和运行 Java 代码 [英] Compiling and Running Java Code in Sublime Text 2

查看:26
本文介绍了在 Sublime Text 2 中编译和运行 Java 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Sublime Text 2 中编译和运行 Java 代码.不要只是告诉我在命令提示符中手动完成.谁能告诉我怎么做?

I am trying to compile and run Java code in Sublime Text 2. Don't just tell me to do it manually in the Command Prompt. Can anyone tell me how?

顺便说一句,我使用的是 Windows 7...

Btw, I am on Windows 7...

推荐答案

所以这就是我添加到 JavaC.sublime-build 文件中的内容

So this is what i added to the JavaC.sublime-build file

{
    "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"
        }
    ]
}

它的作用是为常规构建命令 (ctrl+b) 创建变体.使用 ctrl+b 你仍然可以编译你的代码.如果您执行 shift+ctrl+b 将执行第一个变体,在这种情况下是带有 -Xlint 选项的 javac.第二个也是最后一个变体是 java 命令本身.你可以把它作为你的第一个变体,shift+ctrl+b 将实际执行java代码.

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.

另外,请注意每个变体都是一个名称".这基本上允许这个特定的构建"选项显示在 shift+ctrl+p 选项中.因此,使用此配置,您只需执行 shift+ctrl+p 并键入Run Java"并点击 enter,你的代码就会执行.

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.

希望这有帮助.

这篇关于在 Sublime Text 2 中编译和运行 Java 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆