5

Sometimes you just do some typo in code but compiler will output dozens of errors, (actually it just fails to compile efter the first typo). So it would be very convenient sometimes to limit the compiler output to first error detected. GCC/Clang will accept -Wfatal-errors, can javac do the same? I am using JDK7 for Windows.

exebook
  • 32,014
  • 33
  • 141
  • 226

4 Answers4

6

See this answer: https://stackoverflow.com/a/3115546/500478

You can use -Xmaxerrs and -Xmaxwarns to set the maximal number of errors/warnings before javac gives up.

Community
  • 1
  • 1
Bastien Jansen
  • 8,756
  • 2
  • 35
  • 53
3

Whenever javac generates errors, it will stop "soon after", with or without -Xmaxerrs.

-Xmaxerrs and -Xmaxwarns simply limit the number of messages generated.

2

This worked for me:

javac -Xmaxerrs 1 Test.java
blagae
  • 2,342
  • 1
  • 27
  • 48
1

javac has the -Xmaxerrors option, described in the man page as

-Xmaxerrors number
   Set the maximum number of errors to print.

but I don't know whether -Xmaxerrors 1 will actually cause it to give up after it hits the first error or if it carries on but then only actually prints one error at the end.

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183