Skip to main content
Jump to: navigation, search

SMILA/Documentation/Scripting/Debugging

< SMILA‎ | Documentation‎ | Scripting
Revision as of 10:18, 30 October 2014 by Juergen.schumacher.empolis.com (Talk | contribs) (Created page with "== Debugging Javascripts running in SMILA == You can use the Eclipse JSDT Debug tools to connect to a SMILA process and debug the Javascripts. === Enabling De...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Debugging Javascripts running in SMILA

You can use the Eclipse JSDT Debug tools to connect to a SMILA process and debug the Javascripts.

Enabling Debugging Support

Support for the JSDT debugger must be enabled at program start using system property smila.scripting.debug, for example:

SMILA -Dsmila.scripting.debug=transport=socket,suspend=n,address=9000

See JSDT/Debug/Rhino/Embedding_Rhino_Debugger#The_Connection_String for the full description of this string. The short version:

  • address: the port number to open for the debugger to communicate on. No error will occur or be logged if the port is already in use.
  • suspend: when set to y or true the scripting service will wait for a debugger to connect when initialized. However, as this happens during activation of a Declarative Service, which is limited by a timeout in the DS runtime, an error will occur if you do not connect a debugger within 30 seconds. Thus, suspend=n is usually the better choice.
  • transport: must be socket.


Setting up the debugger

  • Make sure that the "Javascript Development Tools" are installed in your Eclipse installation (use "Install New Software" from Menu "Help". We tested this with version 1.6).
  • Create a launch configuration for the debugger:
    • Go to "Run" -> "Debug Configurations..."
    • Create a new configuration under "Remote JavaScript". Select as Connector the "Mozilla Rhino - Attaching Connector" and enter the SMILA host (e.g. "localhost") and the port you configured above (e.g. 9000)
  • Click "Apply" and "Close"
  • Check the preferences of the Javascript Debugger:
    • Go to "Window" -> "Preferences..."
    • Select "JavaScript" -> "Debug".
    • You may want to enable the option "Suspend for all script loads" so that the debugger stops the script execution immediately when a script is loaded.


Using the Debugger with scripts available in workspace

This should work if you have the scripts running in SMILA available in the workspace, e.g. by having the SMILA.application project from the source code open. So this should be the usual way to work within the SMILA development environment.

  • Start SMILA with debugging enabled (see above).
  • Start the "Remote JavaScript" configuration you created above.
    • Disable the "Suspend for all script loads" option in the JavaScript Debug preferences for now
  • Open the script to debug and set a breakpoint (just like setting breakpoints in Java files: double-click in the grey column at the left side of the editor).
  • Execute the script (e.g. invoke it via http://localhost:8080/smila/script/<script>.<function>).
  • Eclipse should switch to the Debug perspective (it may display a dialog asking you to confirm the switch).
  • The editor should show a copy of the script to debug and the line in which you have set the breakpoint should be marked. You can set additional breakpoints in both versions of the script. However, changes to the script must be done in the original version in SMILA.application.
    • The script copy will be part of a new project "External JavaScript Sources" in your workspace. You can safely delete this project when you are finished with debugging (there is even a preference option so that Eclipse will remove it automatically when you exit the workbench).
  • Use the debugger just like when debugging Java code.

Back to the top