Most of the time when we work with Cocoon we are writing XSLT to do transformations. But sometimes we write Java code to extend the functionality of Cocoon. And that means we want to be able to debug our Java code in NetBeans. Luckily this is easy to accomplish. First we must start Jetty with mvndebug
. This will enable us to attach the NetBeans debugger to Jetty, which runs our Cocoon application.
We open a command prompt and go to the directory with our Cocoon application. In the directory we run the following command: mvndebug jetty:run
. Maven now starts in debug mode. And because Jetty runs in the same process as Maven we also run Jetty in debug mode.
Now in NetBeans we go to Run | Attach Debugger. We get a dialog window with settings. We can leave the settings as-is and press the OK button. NetBeans will now attach the debugger to Jetty. In NetBeans we can set breakpoints in our Java code and debug our code.