Creating a batch file, for simple javac and java command execution

前端 未结 11 2574
终归单人心
终归单人心 2021-02-15 14:18

It is a really simple thing but I cannot get my head around it. I have looked at plenty of StackOverFlow post and as well as on internet.

My goal is to create a .bat whi

11条回答
  •  旧巷少年郎
    2021-02-15 14:45

    I just made a simple batch script that takes a file name as an argument compiles and runs the java file with one command. Here is the code:

    @echo off
    set arg1=%1
    shift
    javac -cp . %arg1%.java
    java %arg1%
    pause
    

    I just saved that as run-java.bat and put it in the System32 directory so I can use the script from wherever I wish.

    To use the command I would do:

    run-java filename
    

    and it will compile and run the file. Just make sure to leave out the .java extension when you type the filename (you could make it work even when you type the file name but I am new to batch and don't know how to do that yet).

提交回复
热议问题