void () { var stdout = System.out; try { var buffer = new ByteArrayOutputStream(); System.setOut(new PrintStream(buffer)); sun.tools.jps.Jps.main(new String[]{"-l"}); var pid = String.valueOf(ProcessHandle.current().pid()); var name = buffer.toString().lines() .filter(l -> l.startsWith(pid)) .map(l -> l.substring(pid.length()).trim()) .findFirst() .orElseThrow(() -> new IllegalStateException("No " + pid + " in: <<<\n" + buffer.toString().trim() + "\n>>>")); stdout.println("main.class=" + name); } finally { System.setOut(stdout); } }