使用.bat脚本包装应用程序

时间:2013-01-09 21:59:25

标签: command-line batch-file

我最近决定开始使用Google的命令行JavaScript编译器(Closure Compiler)来缩小我的Web应用程序中的JavaScript。不幸的是,编译器是用Java编写的,因此我必须键入以使用编译器的命令有点麻烦:

java -jar compiler.jar --js hello.js --js_output_file hello-compiled.js

我最简单的方法是将它包装在.bat文件中,这样我只需键入closure hello.js hello-compiled.js,同时仍允许我使用closure的其他命令行标志,例如--warning-level--help

2 个答案:

答案 0 :(得分:1)

:Start
   @echo off
   if "%1"=="" Echo Error - input and output parameters were not specified.&goto End
   if "%2"=="" Echo Error - output parameter was not specified.&goto End
   if not exist %1 Echo Error - input file does not exist.&goto End
   set infile=%1
   set outfile=%2
   set "params="
:Loop
   if "%3"=="" goto Continue
   set params=%params% %3
   shift
   goto Loop
:Continue
   java -jar compiler.jar --js %infile% --js_output_file %outfile% %params%
   set "infile="
   set "outfile="
   set "params="
:End 

答案 1 :(得分:0)

我不知道您希望这是多么自动化,但这会提示您输入脚本,编译输出文件,以及是否需要任何额外参数。

如果您想要更多选项,可以轻松编辑。

@echo off
set /p script=Script file:
set /p compiled=Compiled script:
set /p params=Enter any extra params (leave blank if none):
if defined params (
java -jar compiler.jar --js %script% --js_output_file %compiled% %params%
) else (
java -jar compiler.jar --js %script% --js_output_file %compiled%
)
echo Done
pause >nul
相关问题