代码之家  ›  专栏  ›  技术社区  ›  Joeri Hendrickx

在eclipse的外部工具中单击stacktrace

  •  1
  • Joeri Hendrickx  · 技术社区  · 15 年前

    我使用Eclipse的externaltools功能来启动我的测试服务器(我不能使用普通的servers视图,因为它不受支持)。

    这很好,但有点遗憾的是,我不能单击stacktraces自动跳转到代码中的那一行(正如您通常所做的那样)。我一直认为eclipse的控制台会自动识别代码行。

    有没有什么方法可以让外部工具做到这一点?

    谢谢

    2 回复  |  直到 15 年前
        1
  •  1
  •   zvikico    15 年前

    您可以将堆栈跟踪复制到Java堆栈跟踪控制台。在控制台中,切换到一个新的Java堆栈跟踪控制台,粘贴堆栈跟踪,它将立即被单击。

    还有,看看 LogViewer plugin

        2
  •  1
  •   EndlosSchleife    7 年前

    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();
            }
        }
    }