X

Geertjan's Blog

  • November 27, 2011

Debugging the NetBeans Platform

Geertjan Wielenga
Product Manager

Once you've set up the NetBeans Platform sources as your NetBeans Platform, you're able to debug the NetBeans Platform itself. That's an occasional question (certainly not a frequent question) on the mailing list and in NetBeans Platform courses: "Is it possible to debug the NetBeans Platform?"

Well, here's how:

  1. Firstly, set up the NetBeans Platform sources as your NetBeans Platform.

  2. Now, open into NetBeans IDE the NetBeans module where you'd like to place a breakpoint. That in itself is the hardest part of this task. I.e., you know you want to debug the NetBeans Platform, but have no idea where to place your breakpoint.

    One way to figure that out, from 7.1 onwards, is to take a visual snapshot of the NetBeans Platform and then analyze that snapshot in NetBeans IDE. To do this, right-click a module that you've set as using the NetBeans Platform sources as your NetBeans Platform and then choose Debug. The application, i.e., the NetBeans Platform, including your custom module, starts up and you'll see this, i.e., NetBeans IDE in debug mode together with your NetBeans Platform application:



    Notice there's a new toolbar button (new in NetBeans IDE 7.1) that resembles an orange camera. Click that button and the IDE creates a visual snapshot of the running application, which in this case is the NetBeans Platform. When you click components in the visual snapshot, the Navigator and Properties window display information about the related GUI component:


By clicking the above components, you can end up identifying the component you'd like to debug and even the module where it is found. Open that module. Set a breakpoint on the line of interest. Right-click the module again and choose Debug. A debug session starts and when the breakpoint is hit, the Debugger in the IDE will open and there you can step through the NetBeans Platform sources.

Join the discussion

Comments ( 6 )
  • Jesse Glick Monday, November 28, 2011

    Of course the GUI snapshot button is only helpful if what you are debugging is the behavior of some GUI component. Often things will be more abstracted so that the code you want to debug is not in the same class or even the same module as the code which physically creates the GUI.


  • Nigel Thomas Friday, February 15, 2013

    Hi Geertjan,

    The post about debugging is nice.

    I would like to know whether there is any option to set a flag whenever the state of a boolean field changes for true to false or vice-versa.

    Regards,

    Nigel.


  • Nigel Thomas Friday, February 15, 2013

    In the above question I would like to clarify that I am using NetBeans 7.0


  • guest Monday, July 14, 2014

    Hi Geertjan. Thanks for the write up. I'm trying this out right now with NetBeans 8.0, but I'm running into a "Build Failed" when I try to debug a module from the sources. I've downloaded the ZIP archive of the build version of the IDE I'm using, which is netbeans-8.0-201403101706-src.zip. After running the ant command referenced in the other post and registering the build as a Netbeans Platform, I open e.g. tomcat5 project. Then I click on Debug. NetBeans starts compiling, and eventually fails with this:

    nbbuild.tryme:

    sh: 0: Can't open /home/kuw/Java/netbeans-source/netbeans-8.0-201403101706-src/nbbuild/netbeans/bin/netbeans

    /home/kuw/Java/netbeans-source/netbeans-8.0-201403101706-src/nbbuild/templates/projectized.xml:402: The following error occurred while executing this line:

    /home/kuw/Java/netbeans-source/netbeans-8.0-201403101706-src/nbbuild/build.xml:925: The following error occurred while executing this line:

    /home/kuw/Java/netbeans-source/netbeans-8.0-201403101706-src/nbbuild/build.xml:1000: exec returned: 127

    BUILD FAILED (total time: 2 minutes 48 seconds)

    Have I missed a step? After clicking Debug and all of the compile messages, the project errors disappear and everything seems ok with the module. But it just won't run (Debug).

    Please help. Thanks.


  • guest Friday, December 12, 2014

    Hi Greertjan - very helpful. I too am also running into the same issue that guest above is hitting. I'm building from mercurial head source. and get the same error:

    jim@jim-VirtualBox:~/projects/nb_main/nbbuild$ ( export ANT_OPTS="-Xms512m -Xmx1024m"; ant -v tryme ; )

    [.... whole lot of output ....]

    tryme:

    [property] Loading Environment env.

    Property "env.NBDISPLAY" has not been set

    [available] Unable to find /usr/lib/jvm/java-7-openjdk-i386/jre/lib/amd64

    [exec] Current OS is Linux

    [exec] Setting environment variable: DISPLAY=:0

    [exec] Executing 'sh' with arguments:

    [exec] '/home/jim/projects/nb_main/nbbuild/netbeans/bin/netbeans'

    [exec] '--jdkhome'

    [exec] '/usr/lib/jvm/java-7-openjdk-i386'

    [exec] '--userdir'

    [exec] '/home/jim/projects/nb_main/nbbuild/testuserdir'

    [exec] '-J-Dnetbeans.full.hack=true'

    [exec]

    [exec] The ' characters around the executable and arguments are

    [exec] not part of the command.

    [exec] sh: 0: Can't open /home/jim/projects/nb_main/nbbuild/netbeans/bin/netbeans

    BUILD FAILED

    /home/jim/projects/nb_main/nbbuild/build.xml:1000: exec returned: 127

    at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:646)

    at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:672)

    at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:498)

    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)

    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.lang.reflect.Method.invoke(Method.java:606)

    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)

    at org.apache.tools.ant.Task.perform(Task.java:348)

    at org.apache.tools.ant.Target.execute(Target.java:390)

    at org.apache.tools.ant.Target.performTasks(Target.java:411)

    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)

    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)

    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)

    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)

    at org.apache.tools.ant.Main.runBuild(Main.java:809)

    at org.apache.tools.ant.Main.startAnt(Main.java:217)

    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)

    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

    Total time: 1 second


  • guest Thursday, June 23, 2016

    The "Take GUI Snapshot" tool is easily the awesomest thing I've seen all week. Thanks!


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.