Java compilation errors limited to 100

房东的猫 提交于 2019-12-20 09:43:07

问题


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


回答1:


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 -Xmaxerrs and -Xmaxwarns




回答2:


If you're using gradle:

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



回答3:


Have you tried the -Xmaxerrors command line option? go here and search for "maxerrors"




回答4:


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




回答5:


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—way more 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.

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.




回答6:


And if your using ant, make sure to use

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

and not

<compilerarg value="-Xmaxerrs 5"/>

I always forget.




回答7:


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

<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




回答8:


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.



来源:https://stackoverflow.com/questions/3115537/java-compilation-errors-limited-to-100

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!