1

: 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
4

2 に答える 2

2

単純なバージョンに書き直してみてください:

cls

$wd = [System.IO.Directory]::GetCurrentDirectory();

# Build Closure Compiler command line call
$cmd = "-jar $wd\..\ClosureCompiler\compiler.jar";

$arrayOfJs = Get-ChildItem -Recurse -Include "*.js" | % { "--js $_.FullName" };

$cmd += [string]::Join(" ", $arrayOfJs);

Invoke-Expression "java $cmd --js_ouput_file $wd\all.js"
于 2012-08-25T09:46:05.210 に答える
1

あなたがするとき

$cmd = @(...);

配列を作成しているため、後続の+=要素は配列に追加されており、文字列連結ではありません。文字列として、または $cmd を使用する前にそれを持ってください。次のようにします。

$cmd -join " "

要素を結合して、スペースで区切られた単一の文字列にします。デフォルトでは、配列が文字列に変換されると、要素間に改行が表示されます。

于 2012-08-25T10:18:35.587 に答える