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

前端 未结 11 2576
终归单人心
终归单人心 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:31

    I've also faced a similar situation where I needed a script which can take care of javac and then java(ing) my java program. So, I came up with this BATCH script.

    ::  @author Rudhin Menon
    ::  Created on 09/06/2015
    ::
    ::  Auto-Concrete is a build tool, which monitor the file under
    ::  scrutiny for any changes, and compiles or runs the same once
    ::  it got changed.
    ::  
    ::  ========================================
    ::  md5sum and gawk programs are prerequisites for this script.
    ::  Please download them before running auto-concrete.
    ::  ========================================
    ::  
    ::  Happy coding ...
    
    @echo off
    
    :: if filename is missing
    if [%1] EQU [] goto usage_message
    
    :: Set cmd window name
    title Auto-Concrete v0.2
    
    cd versions
    
    if %errorlevel% NEQ 0 (
        echo creating versions directory
        mkdir versions
        cd versions
    )
    
    cd ..
    
    javac "%1"
    
    :loop
        :: Get OLD HASH of file
        md5sum "%1" | gawk '{print $1}' > old
        set /p oldHash= new
        set /p newHash=nul
            goto inner_loop
        )
    
        :: Once they differ, compile the source file
        :: and repeat everything again
        echo.
        echo ========= %1 changed on %DATE% at %TIME% ===========
        echo.       
        javac "%1"
    goto loop
    
    :usage_message
    echo Usage : auto-concrete FILENAME.java
    

    Above batch script will check the file for any changes and compile if any changes are done, you can tweak it for compiling whenever you want. Happy coding :)

提交回复
热议问题