In Code: System.out.println(\"myPackage.MyClass\");
In Eclipse Console: myPackage.MyClass.myMethod
I want to click on the output (myPackage.MyClass.myM
Here's a simple wrapper method based on everyone else's answers that can be used anywhere to get a string formatted so that the Eclipse console will link to the line in any file where getSourceCodeLine() is called. I also discovered that printing to System.err in Eclipse will be shown in red.
public static String getSourceCodeLine() {
// An index of 1 references the calling method
StackTraceElement ste = new Throwable().getStackTrace()[1];
return "(" + ste.getFileName() + ":" + ste.getLineNumber() + ")";
}
public static void main( String[] args )
System.out.println("Here's a link to " + getSourceCodeLine());
System.err.println("And a red link to " + getSourceCodeLine());
}