I am trying to write a program which can extract all the compiler errors (or other things like bad build paths) from Eclipse's "Problems" view.
I have not been able to find any documentation on how this might be done.
I've got three possible solutions for you:
This is the easiest way to go. Eclipse is producing a visual presentation of build errors, and you want a structured presentation, so they're a bad match.
On the other hand, if you just run javac
from the command-line, the output is easy to capture and relatively easy to parse right there. If you need to be more precise in parsing the errors, look at running JavaCompiler
in your code and providing a custom DiagnosticListener
to it.
If it's important that you capture some nuances of the Eclipse compiler, you can even run that from the command line (in batch mode). There's a nice blog post that describes the process here: ECJ - Eclipse Compiler for Java. Here's the short version: find the ECJ jar in your Eclipse distribution (mine is in plugins/org.eclipse.jdt.core_3.8.3.v20130121-145325.jar
) and run it on the command line as
java -jar <ecj.jar> <sourcefiles>
Naturally, you can also run this from within Java for finer control.
This will be clumsy, but could be useful for testing scenarios, where you want an automated tester to verify that an Eclipse project builds the way you expect.
You can use a tool like AutoHotKey or Sikuli or the AWT Robot to automatically fetch the errors. The simplest routine I can think of goes like this:
Finally, if want you really need is some kind of real-time capture of error messages that's transparent to the user, then you're stuck with this.
You'll need to go into the Eclipse source code, probably the definition of the "Problems" view and modify it to pass your code information on the side. Then whoever needs this will have to use your custom-built version of Eclipse and not the standard version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With