【问题标题】:Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableList.toImmutableList()Ljava/util/stream/Collector;线程“主”java.lang.NoSuchMethodError 中的异常:com.google.common.collect.ImmutableList.toImmutableList()Ljava/util/stream/Collector;
【发布时间】:2020-06-01 11:15:16
【问题描述】:

我在 Google 中使用 Closure Compiler。我是这方面的初学者。当我运行我的代码时,我得到一个错误。
我想知道是什么原因,或者有没有使用demo。

我的代码:

public class JsClosureCompiler {
    public static String compileJs(String code){

        Compiler compiler = new Compiler();

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

        // To get the complete set of externs, the logic in
        // CompilerRunner.getDefaultExterns() should be used here.
        SourceFile extern = SourceFile.fromCode("externs.js",
                "function textDiv(text){};");

        // The dummy input name "input.js" is used here so that any warnings or
        // errors will cite line numbers in terms of input.js.
        SourceFile input = SourceFile.fromCode("input.js", code);

        // compile() returns a Result, but it is not needed here.
        compiler.compile(extern, input, options);

        // The compiler is responsible for generating the compiled code; it is not
        // accessible via the Result.
        if(compiler.getErrorCount() > 0){
            StringBuilder erroInfo = new StringBuilder();
            for(JSError jsError: compiler.getErrors()) {
                erroInfo.append(jsError.toString());
            }
        }
        return compiler.toSource();
    }

    public static void main(String[] args) {
        String code = "function makeNoteDom(noteTitle, noteContent, noteContainer) {\n" +
                "  // Create DOM structure to represent the note.\n" +
                "  var headerElement = textDiv(noteTitle);\n" +
                "  var contentElement = textDiv(noteContent);\n" +
                "\n" +
                "  var newNote = document.createElement('div');\n" +
                "  newNote.appendChild(headerElement);\n" +
                "  newNote.appendChild(contentElement);\n" +
                "\n" +
                "  // Add the note's DOM structure to the document.\n" +
                "  noteContainer.appendChild(newNote);\n" +
                "}\n" +
                "\n" +
                "/**\n" +
                " * Iterates over a list of note data objects and creates a DOM\n" +
                " */\n" +
                "function makeNotes(data, noteContainer) {\n" +
                "  for (var i = 0; i < data.length; i++) {\n" +
                "    makeNoteDom(data[i].title, data[i].content, noteContainer);\n" +
                "  }\n" +
                "}\n" +
                "\n" +
                "function main() {\n" +
                "  var noteData = [\n" +
                "      {title: 'Note 1', content: 'Content of Note 1'},\n" +
                "      {title: 'Note 2', content: 'Content of Note 2'}];\n" +
                "  var noteListElement = document.getElementById('notes');\n" +
                "  makeNotes(noteData, noteListElement);\n" +
                "}\n" +
                "\n" +
                "main();";
        String s = compileJs(code);
        System.out.println(s);
    }
}

--------------------------------错误--错误----------- ---------------------

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableList.toImmutableList()Ljava/util/stream/Collector;
    at com.google.javascript.jscomp.deps.DependencyInfo$Require.asSymbolList(DependencyInfo.java:60)
    at com.google.javascript.jscomp.deps.DependencyInfo$Base.getRequiredSymbols(DependencyInfo.java:163)
    at com.google.javascript.jscomp.Compiler.findModulesFromInput(Compiler.java:1901)
    at com.google.javascript.jscomp.Compiler.findModulesFromEntryPoints(Compiler.java:1857)
    at com.google.javascript.jscomp.Compiler.parseInputs(Compiler.java:1666)
    at com.google.javascript.jscomp.Compiler.parseForCompilationInternal(Compiler.java:939)
    at com.google.javascript.jscomp.Compiler.lambda$parseForCompilation$4(Compiler.java:922)
    at com.google.javascript.jscomp.CompilerExecutor$2.call(CompilerExecutor.java:102)
    at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
    at java.util.concurrent.FutureTask.run(FutureTask.java)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

【问题讨论】:

    标签: java closures


    【解决方案1】:

    将番石榴放入 pom.xml

    <dependency>
       <groupId>com.google.guava</groupId>
       <artifactId>guava</artifactId>
       <version>22.0</version>
    </dependency>
    

    【讨论】:

      猜你喜欢
      • 2019-02-21
      • 1970-01-01
      • 1970-01-01
      • 2020-07-30
      • 1970-01-01
      • 2018-02-01
      • 2015-07-09
      • 1970-01-01
      • 2021-12-15
      相关资源
      最近更新 更多