注意:Java/Closure Compiler 的实际错误来自--js- out putfilet
中的缺失!
我有这个 PowerShell 脚本:
cls
$jsFiles = @();
Get-ChildItem | Where {$_.PsIsContainer} | Foreach {
$dir = $_.FullName;
$jsFile = $dir + "\" + $_.Name + ".js";
if (Test-Path ($jsFile)) {
$jsFiles += $jsFile;
}
}
$wd = [System.IO.Directory]::GetCurrentDirectory();
# Build Closure Compiler command line call
$cmd = @("-jar $wd\..\ClosureCompiler\compiler.jar");
Foreach ($file in $jsFiles) {
# Both insert a newline!
$cmd += "--js $file";
#$cmd = "$cmd --js $file";
}
$cmd = "$cmd --js_ouput_file $wd\all.js";
Invoke-Expression "java.exe $cmd"
问题是每个+=
或$cmd = "$cmd str"
调用都插入了换行符!
Echoargs 给了我这个输出:
Arg 0 is <-jar>
Arg 1 is <S:\ome\Path\compiler.jar>
Arg 2 is <--js>
Arg 3 is <S:\ome\Path\script1.js>
Arg 4 is <--js>
Arg 5 is <S:\ome\Path\script2.js>
...
Arg 98 is <--js_ouput_file>
Arg 99 is <S:\ome\Path\all.js>
(可能)因此,我收到一些错误java.exe
:
java.exe : "--js_ouput_file" is not a valid option
At line:1 char:1
+ java.exe -jar ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: ("--js_ouput_file" is not a valid option:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError