Compiling and Running Java Code in Sublime Text 2

前端 未结 19 2817
执念已碎
执念已碎 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 01:54

    I find the method in the post Compile and Run Java programs with Sublime Text 2 works well and is a little more convenient than the other methods. Here is a link to the archived page.

    For Windows:

    Step 1:

    Create runJava.bat with the following code.

    @ECHO OFF
    cd %~dp1
    ECHO Compiling %~nx1.......
    IF EXIST %~n1.class (
    DEL %~n1.class
    )
    javac %~nx1
    IF EXIST %~n1.class (
    ECHO -----------OUTPUT-----------
    java %~n1
    )
    

    Copy this file to jdk bin directory.

    Step 2:

    1. Open Sublime package directory using Preferences > Browse Packages..
    2. Go to Java Folder
    3. Open JavaC.sublime-build and replace line
      "cmd": ["javac", "$file"],
      with
      "cmd": ["runJava.bat", "$file"],

    Done!

    Write programs and Run using CTRL + B

    Note: Instructions are different for Sublime 3.

提交回复
热议问题