2011-07-09 3 views
0

タイトルによれば、Java APIを使用してプログラムでGoogle Closure Compilerに定義を渡したいと思います。は、Javaを介してGoogle Closure Compilerに定義されています

これは私の現在のコードです:あなたはdefine replacements mapを移入したい

com.google.javascript.jscomp.Compiler.setLoggingLevel(Level.INFO); 
com.google.javascript.jscomp.Compiler compiler = new com.google.javascript.jscomp.Compiler(); 
CompilerOptions options = new CompilerOptions(); 
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options); 
WarningLevel.VERBOSE.setOptionsForWarningLevel(options); 

List<JSSourceFile> externs = new ArrayList<JSSourceFile>(); 
externs.add(JSSourceFile.fromFile(extern_src)); 

List<JSSourceFile> primary = new ArrayList<JSSourceFile>(); 
primary.add(JSSourceFile.fromFile(tmp)); 
compiler.compile(externs, primary, options); 
for (JSError message : compiler.getWarnings()) { 
    System.err.println("Warning message: " + message.toString()); 
} 

for (JSError message : compiler.getErrors()) { 
    System.err.println("Error message: " + message.toString()); 
} 

答えて

0

options.getDefineReplacements().put("myDefineVarName", value); 

値はブール値、数値、文字列リテラルであるNodeなければなりません。 はブールリテラルの使用のために両方NodeTokenがパッケージcom.google.javascript.jscomp.rhinoからです

new Node(Token.TRUE) 

のような値を値を作成します。

私はToken.STRINGToken.NUMBERが他の種類の値のトークンタイプだと考えていますが、私にはそれを引用していません。

関連する問題