Debugging Code


To debug code running in the server it also has to be in a project in the Workbench. The simplest way to do this is to create it in the Workbench and deploy it to webMathematica. There is a wizard to create a webMathematica project and the Server view has a tool to deploy the project to the server. Note that the project has to exist before you can connect with the debugger. Also, your code must be loaded after the connection has been made.

A restriction is that you can only set breakpoints on code that is in .m files; you cannot set a breakpoint on code that is in a JSP. However, you need to have a JSP that loads a Mathematica package. An example of a JSP is shown below.

Debug Code

Note how the JSP loads the package, Project1`, and then invokes one of its functions. Here is the source of the package as seen in the Workbench Mathematica source editor.

Debug Code

Note the blue dot in the left margin: this represents a breakpoint. When the JSP is run it executes the code and this hits the breakpoint. The Workbench then switches to handle the breakpoint, displaying information such as the kernel execution stack, source code, and variables. A view of the kernel execution stack is shown below.

Debug Code

If you spend too much time at the breakpoint then the webMathematica server might terminate the kernel. In this case you might want to change configuration to increase the KernelTimeLimit in the MSPConfiguration.xml file.

Locating the Code

In order for breakpoints to work it is important that you locate the code in the server and the Workbench in compatible locations.

When your project is deployed, Mathematica source code is deployed into the web application inside WEB-INF/Applications. You need to make sure that the path to the code from within the Workbench is consistent with that in the web application. For example, if you had your code in the top of your project in an application Project1/Project1.m, then it would have to be located as WEB-INF/Applications/Project1/Project1.m.

If you wanted to locate your code more deeply, you would have to make a setting of the Mathematica project resources.