Thursday, August 11, 2011

Generating JAR via batch file with error checks

@SET JAR=miteff.com.jar
del %JAR%
cd some-folder\
@IF NOT %ERRORLEVEL% == 0 GOTO ERROR
del *.class
@IF NOT %ERRORLEVEL% == 0 GOTO ERROR
javac *.java
@IF NOT %ERRORLEVEL% == 0 GOTO ERROR
cd ..\..\..
@IF NOT %ERRORLEVEL% == 0 GOTO ERROR
javac *.java
@IF NOT %ERRORLEVEL% == 0 GOTO ERROR
jar -cf %JAR% .
@IF NOT %ERRORLEVEL% == 0 GOTO ERROR
@dir %JAR%
IF NOT %ERRORLEVEL% == 0 GOTO ERROR
@echo Copy the jar to dest folder...
@copy /y %JAR% X:\

@echo Seems everything to be fine, end with success
@Goto :END

:ERROR
@echo Error, stopping script...
@rem Pause if the script is run in a window (not from command prompt)
@ping -n 10 localhost > nul

:END

No comments:

Post a Comment