开发者

javac flag to print only the error locations

Is it possible to make javac output only the error locations and the error messages, and hide the source code dump?

Now I get:

$ javac t.java
t.java:1:开发者_开发百科 <identifier> expected
class {
     ^
t.java:2: reached end of file while parsing
bar
   ^
t.java:4: reached end of file while parsing

^
3 errors

I want to get only:

$ javac ... t.java
t.java:1: <identifier> expected
t.java:2: reached end of file while parsing
t.java:4: reached end of file while parsing


I think there is no flag you could pass to javac, but you can simply filter the output through any program which removes the superfluous lines. Here an example with grep:

javac t.java 2>&1 | egrep '^[a-zA-Z0-9_/]+\.java:[0-9]+: '

You might have to change the part matching the file name if you have strange letters in your file name - this seems to work for the ASCII subset.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜