简体   繁体   中英

How do I write to the Netbeans Debugger Console (in Java)?

Netbeans has a tabbed window in the Output section called "Debugger Console". Is it possible to write a message to this window using Java? If so, how?

The messages you see in the debugger console are either

  1. informations given by the debugger itself (breakpoint added, for example)
  2. custom messages associated with a breakpoint

When you add a breakpoint to a line of code, the default behavior of the breakpoint is to suspend the thread that executed the line of code, and to print the text "Breakpoint hit at line {lineNumber} in class {className} by thread {threadName}." .

You can configure a breakpoint to print a custom text. This text will be output in the debugger console when it reaches the breakpoint. To do so, right click on a breakpoint, open the propoerties window, and enter your text in the field Print text .

A useful trick is to configure a breakpoint so that it does not block ( suspend : no thread ), and to enter a text. The effect is the same than adding println lines in your code, but the benefit is that you don't have to recompile the code, and it's easier to activate/deactivate these debugger logs (and it obviously does not stay on production code).

Note that, in the text of the breakpoint, you can use one of the special values {lineNumber} , {methodName} , {className} or {threadName} , and you can also evaluate some code with the syntax {=xxx} . Just replace xxx with a variable name, or a method call, or whatever.

OK for me it's in Output > Glassfish server 3+ Console

I wrote a simply System.out.println in my program and when the debugger arrive on this instructions the console diplay the result of my simply writing.

For others situation I don't know

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM