Java 编译错误限制为 100

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3115537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 00:26:19  来源:igfitidea点击:

Java compilation errors limited to 100

javajavac

提问by openssid

I have a Java file,which when I compiled, I will be able to see only first 100 errors on console after that java compiler(javac) exits. How will I be able to see all the compilation errors on console? Thanks in advance- opensid

我有一个 Java 文件,当我编译它时,在 java 编译器(javac)退出后,我将只能在控制台上看到前 100 个错误。我如何才能在控制台上看到所有编译错误?提前致谢 - opensid

采纳答案by krock

Generally the compiler will give up after 100 errors. Most of the errors after this point will likely be caused by one of the first errors. If you must have more errors check out the javac options -Xmaxerrsand -Xmaxwarns

通常编译器会在 100 个错误后放弃。此后的大多数错误很可能是由第一个错误引起的。如果您必须有更多错误,请查看 javac 选项 -Xmaxerrs-Xmaxwarns

回答by DallinDyer

If you're using gradle:

如果您使用的是 gradle:

allprojects {
  gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xmaxerrs" << "1000"
    }
  }
}

回答by Peter Recore

Have you tried the -Xmaxerrorscommand line option? go hereand search for "maxerrors"

您是否尝试过-Xmaxerrors命令行选项?去这里搜索“maxerrors”

回答by Jim

And if your using ant, make sure to use

如果您使用ant,请确保使用

<compilerarg value="-Xmaxerrs"/>
<compilerarg value="5"/>

and not

并不是

<compilerarg value="-Xmaxerrs 5"/>

I always forget.

我总是忘记。

回答by Suketu Bhuta

In case you are using ant, the following will work :

如果您使用的是ant,以下内容将起作用:

<compilerarg line="-Xmaxerrs 10000" />

Note that you are using the "line" argument rather than "value" argument as in the answer above https://stackoverflow.com/a/42396745/2200690

请注意,您使用的是“line”参数而不是“value”参数,如上面的答案https://stackoverflow.com/a/42396745/2200690

回答by trashgod

If you're using Eclipse, Preferences > Java > Compiler > Building > Generalwill let you specify more problems per unit.

如果您使用 Eclipse,Preferences > Java > Compiler > Building > General将让您指定每个单元的更多问题。

回答by JUST MY correct OPINION

The Java compiler gives up after a certain number of errors when compiling a file because Java is one of those languages that's hard to re-synch source to expected state after an error. This means that one single misplaced semi-colon can generate dozens of errors (or more—waymore in some extreme edge cases) that have little to nothing to do with the actual error. There's no point in printing out "all the errors" in your source code because the majority of them are likely phantom errors.

在编译文件时出现一定数量的错误后,Java 编译器会放弃,因为 Java 是一种在出现错误后很难将源重新同步到预期状态的语言。这意味着,一个单一的放错位置的分号可以产生几十个错误(或更多-的方式更在一些极端的边缘情况)有小到无事可做与实际误差。打印出源代码中的“所有错误”是没有意义的,因为它们中的大多数可能是幻影错误。

Fix the first few clear, understandable errors you can find in your compiler output and try again. (Don't forget to look for variants of those errors in the rest of your source!) Getting more error messages per compile run will probably not help and will instead, in fact, just serve to bewilder and dishearten.

修复您可以在编译器输出中找到的前几个清晰易懂的错误,然后重试。(不要忘记在源代码的其余部分中查找这些错误的变体!)每次编译运行获得更多错误消息可能无济于事,事实上,只会让人感到困惑和沮丧。

回答by User 1034

If you are using Windows operating system then try to compile your sources using Command Prompt. Then that command prompt won't exit on errors.

如果您使用的是 Windows 操作系统,请尝试使用命令提示符编译您的源代码。然后该命令提示符不会因错误而退出。