开发者

Click stacktrace in eclipse's external tools

I'm using Eclipse's external tools functionality to launch my test server (I can't use the normal servers view for it since it's not su开发者_如何学Cpported).

That works fine, but it's a bit sad that I can't click the stacktraces to automatically jump to that line in the code (as you could normally do). I always thought eclipse's console automatically recognized lines of code.

Is there any way to make it do that for external tools?

Thanks


You can copy the stack trace to a Java Stack Trace console. In the Console, switch to a new Java Stack Trace console, paste the stack trace and it will be immediately clickable.

Also, check out the LogViewer plugin, as far as I can recall, it can do that with less effort


As a workaround, I created a simple Java wrapper program which executes the command given as arguments. This allows an Eclipse Java run configuration to be used instead of an external tool.

public class Exec {
    private final Process process;
    private boolean error;

    public Exec(Process process) {
        this.process = process;
    }

    public static void main(String[] command) throws Exception {
        new Exec(Runtime.getRuntime().exec(command)).run();
    }

    public void run() throws Exception {
        Thread thread = new Thread(() -> copy(process.getInputStream(), System.out));
        thread.start();
        copy(process.getErrorStream(), System.err);

        int status = process.waitFor();
        thread.join();
        System.err.flush();
        System.out.flush();
        System.exit(status != 0 ? status : error ? 1 : 0);
    }

    private void copy(InputStream in, OutputStream out) {
        try {
            byte[] buffer = new byte[4096];
            for (int count; (count = in.read(buffer)) > 0;) {
                out.write(buffer, 0, count);
            }
        } catch (IOException e) {
            error = true;
            e.printStackTrace();
        }
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜