2011-07-09 23 views
0

正如标题所说,我想通过Java API以编程方式将定义传递给Google Closure编译器。传递通过Java定义到Google Closure编译器

这是我当前的代码:

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

要填充的define replacements map

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

的值必须是一个Node这是一个布尔值,数字,或字符串文字。 要为布尔值使用创建一个值等

new Node(Token.TRUE) 

其中两个NodeToken是从包com.google.javascript.jscomp.rhino的值。

我相信Token.STRINGToken.NUMBER是其他类型的值的标记类型,但不引用我。

相关问题