I'm wondering if there is any option to print something to console on breakpoint. I had an idea to hack conditional breakpoints feature in IntelliJ IDEA.
I wrote such a class:
public class BreakpointPrinter {
public static boolean print(Object object){
System.out.println(object);
return false;
}
}
but unfortunately I get an error:
Do you have any better ideas to achieve such a goal?
Right click on the breakpoint:
Click on More
Select Evaluate and log
and enter the code you want to execute.
In the above example the breakpoint executes System.out.println("I reached my breakpoint")
and as soon as the breakpoint is reached that string is written to the IntelliJ console.
I suspect the reason you are getting a ClassNotFoundException
is that your class (BreakpointPrinter
) is not on the classpath for the JVM instance spawned by IntelliJ. However, if all you want to do is write to console everytime a specific breakpoint is reached then you can do so using a class which is always available in the JVM (e.g. java.lang.System
) and you can trigger it via the breakpoint's Evaluate and log
feature.