Исключение в потоке "main" java .lang.NoSuchMethodError: com.google.common.collect.ImmutableList.toImmutableList () Ljava / util / stream / Collector; - PullRequest
0 голосов
/ 29 мая 2020

Я использую компилятор Closure в Google. Я в этом новичок. Когда я запускаю свой код, я получаю сообщение об ошибке.
Я хочу знать, в чем причина или использовалась ли какая-либо демонстрация.

мой код :

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)

1 Ответ

0 голосов
/ 01 июня 2020

положить гуаву в помпон. xml

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