40

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

skaffman
  • 398,947
  • 96
  • 818
  • 769
openssid
  • 711
  • 3
  • 8
  • 18
  • 1
    there is most likely a single error that is causing all the subsequent errors. All the rest of the errors are not relevant if you fix the root cause. –  Jun 25 '10 at 04:33
  • upon further reflection there might be an obscure reason to want to see the total. maybe for keeping a metric of how bad some particular code base is? still seems a bit dubious to me though. – Peter Recore Jun 25 '10 at 04:35
  • Since the overwhelming majority of the error messages are likely phantom messages, @Peter Recore, yeah, that would be a dubious metric. ;) – JUST MY correct OPINION Jun 25 '10 at 04:39
  • 1
    Thanks all with -Xmaxerrs I am able to get the all error!!! – openssid Jun 25 '10 at 04:59
  • Maybe you should borrow a book for learning Java. http://www.ibiblio.org/java/books.html or just follow the Java Tutorial on suns website http://java.sun.com/docs/books/tutorial/... – Martijn Courteaux Jun 25 '10 at 07:47
  • @Peter It can also arise in a large porting project when you're breaking a dependency that won't build. – Pr0methean Oct 17 '16 at 15:57

8 Answers8

40

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

krock
  • 28,904
  • 13
  • 79
  • 85
22

If you're using gradle:

allprojects {
  gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xmaxerrs" << "1000"
    }
  }
}
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
DallinDyer
  • 1,378
  • 13
  • 14
5

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

Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
Peter Recore
  • 14,037
  • 4
  • 42
  • 62
4

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

Suketu Bhuta
  • 1,871
  • 1
  • 18
  • 26
2

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

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
2

And if your using ant, make sure to use

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

and not

<compilerarg value="-Xmaxerrs 5"/>

I always forget.

Jim
  • 463
  • 4
  • 7
1

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.

JUST MY correct OPINION
  • 35,674
  • 17
  • 77
  • 99
  • I was interested in knowing how much errors may occur by simple mistakes. – openssid Jun 25 '10 at 05:02
  • 1
    You won't find it. That's the point. Most of the errors are phantom errors caused by parser limitations (and the nigh-unparseable nature of Java). All you'll find is that the compiler is really stupid and can't figure out real errors vs. "errors of misopportunity". – JUST MY correct OPINION Jun 25 '10 at 06:00
  • I don't know why you think Java is 'one of those languages that's hard to re-synch source to expected state after an error' and 'nigh-unparseable'. It's a pretty standard semicolon-terminator language, of the kind we've been building solid parsers for for decades, and parsers do have error recovery in them, since the 1970s if not earlier. Cascading compile errors are more usually due to undeclared identifiers and other *semantic* errors. – user207421 Jun 25 '10 at 07:12
  • And yet many other languages, when faced with such semantic errors, don't spew dozens to hundreds of error messages. They seem to have the smarts to figure out what such an error causes in later code and know, thereby, how to ignore it. C, C++ and Java compilers can't seem to figure this out. – JUST MY correct OPINION Jun 25 '10 at 08:22
  • Eclipse, (and all the other ide's I'm sure) don't seem to have much problem recovering. they don't paint my entire screen red with squigglies when i have an error, just the appropriate sections. – Peter Recore Jun 25 '10 at 14:07
  • 'And yet ...' ... this is still nothing to do with Java being 'nigh-unparseable'. I haven't noticed that Java is prone to cascading errors, syntactical or semantic, but then I don't compile source code that gives 100 compiler errors. FYI C and C++ are both much harder to parse than Java: both have typedefs, which require semantic feedback to disambiguate them, and C++ has > 50 shift/reduce conflicts, showing that syntax design wasn't exactly Stroustrup's greatest strength. Java doesn't have either of these problems. In short I don't see any basis for your claims. – user207421 Jun 27 '10 at 05:46
0

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.

Puru
  • 8,913
  • 26
  • 70
  • 91
  • Then you can compile that using the Terminal. If you still not able to see then use printStack method to print the error message in a file. – Puru Jun 25 '10 at 05:10
  • Yes Purushotham, I am using Terminal, but I was having compilation errors, I was interested in knowing errors beyond 100, With "javac -Xmaxerrs 200" I am able to see 200 errors. – openssid Jun 25 '10 at 11:02