如何在Java内部使用“ closure-compiler”

时间:2019-06-20 14:47:18

标签: java google-closure-compiler rhino

我使用的是Google提供的闭包编译器。我在字符串变量中有JavaScript。需要在Java中使用闭包编译器来压缩字符串

我已经尝试了以下链接http://blog.bolinfest.com/2009/11/calling-closure-compiler-from-java.html的代码

这是我使用的代码,其中“ source”变量具有javascript的值

Compiler compiler = new Compiler();

CompilerOptions options = new CompilerOptions();
// Advanced mode is used here, but additional options could be set, too.

CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);

compiler.compile(source, options);

return compiler.toSource();

我在以下行中有错误:compiler.compile(source, options);

1 个答案:

答案 0 :(得分:1)

Compiler.complier()方法不需要2个参数,但需要3个参数。

看看这个link。 您将了解所调用方法所需的参数数量和种类。