0

Whenever a compilation results in an error output longer then one screen, I have to scroll back to see the first error (possibly a cause of the later ones) and fix it. This is especially a pain in Screen, where I first have to press ctrl+a Esc to scroll.

Is there a command line switch in javac that lets the error messages be displayed in reverse order, or is there some generic command line magic I can achieve the same effect with?

Update: Just to clarify, I always use the command line for compilation, an IDE is not an option.

6
  • 1
    How about using an IDE? Commented Aug 3, 2013 at 18:39
  • On a Linux, there is naturally a trivial way: javac ... | tail -r But personally, I'd use javac ... | less, which automatically gives me the first screen of output. Commented Aug 3, 2013 at 18:40
  • @assylias see my update, I can’t stand IDEs. Commented Aug 3, 2013 at 18:49
  • @MarkoTopolnik Tail complains there is no -r switch. Oddly, less scrolls the output to the end, as if it weren’t piped through it at all. Commented Aug 3, 2013 at 18:51
  • 1
    @JoóÁdám Then you probably don't realise what you are missing... Commented Aug 3, 2013 at 19:06

2 Answers 2

3

If you want to stop on the first compilation error, then you should probably use -Xmaxerrs 1. You can fix that error and compile again.

Edit If you are under *nix environment, redirecting stderr to stdout will make most of the tools like head, more, less work. Compilation errors are printed to stderr.

javac File.java 2>&1 | less

Edit2 You could also send it to a file using -Xstdout filename

Sign up to request clarification or add additional context in comments.

1 Comment

Technically not an answer to the question, but I will accept it, because -Xmaxerrs 1 works really nice for me. Thanks!
1

Pipe the output to more on command-line or better use an IDE like Eclipse.

javac file.java | more

Now press space bar to let the output scroll (or enter for line by line) if it's more than one screen page.

3 Comments

more, just like less, displays the entire output, scrolling to the last line (which I don’t understand either).
That's indicative of a program writing info to stderr, not stdout.
@RichardSitze Yeah, it crossed my mind, but I thought at the end of the day by default the pipe takes both stdout and stderr.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.