Compiling and Running Java Code in Sublime Text 2

前端 未结 19 2741
执念已碎
执念已碎 2020-11-28 01:20

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?

Btw, I am on Windows

19条回答
  •  难免孤独
    2020-11-28 02:01

    I followed a post in this thread and got it working perfectly:

    Make the bat file with the following, and save it anywhere in your PATH. I suggest C:\Program Files\Java\jdk*\bin\ to keep everything together.

    @ECHO OFF
    cd %~dp1
    javac %~nx1
    java %~n1
    

    then edit C:\Users\your_user_name\AppData\Roaming\Sublime Text 2\Packages\Java\JavaC.sublime-build, the contents will be

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

    replace "javac" with the name of your bat file (for instance, javacexec.bat) and save it.

提交回复
热议问题