Sometimes it's necessary to debug code to find a bug — it happened to me too. Back then, our only solution was to use tools like “groovyIDE”, where we could print output to the console, just like old-school PHP developers.
A few months ago, I published a Visual Studio Code extension that provides similar functionality to “groovyIDE” but for a local environment. This local setup also supports external libraries, such as JWT libraries.
The new version of the VS Code extension now allows debugging Groovy scripts locally using JDI (Java Debug Interface). I developed a tool that enables this functionality. Currently, it does not support all Java or Groovy classes.
What do you need?
Before using the extension, you need to configure it properly.
If you've installed Java and Groovy or manually added them to your system PATH, you can find their locations by running the following command in Command Prompt:
This will show you the installation paths for Java and Groovy.
Open VS Code Settings and search for "Groovy" to configure the extension.
After completing these steps, the VS Code extension will be ready to use for local Groovy script debugging.
There are three ways to create a project:
Using the wizard – This method creates a folder and an example script.
In VS Code, open the Command Palette, type >cpi, and select SAP CPI: Create a SAP CPI Groovy Script Project.
It will prompt you to select a folder and enter a name for the project.
After providing the folder and project name, a new project is created automatically.
Using SAP CPI Tools Extension – This method creates a project containing the Groovy script code from SAP CPI.
In VS Code, open the Command Palette, type >cpi, and select SAP CPI: Create a SAP CPI Groovy Script from CPI Extension.
It will prompt you to select a folder and enter a name for the project.
VS Code is listening for a connection from the SAP CPI Extension.
It will create a project containing the script from SAP CPI.
Using SAP CPI Tools Extension with trace files (Header, properties and body) - This method is the same as Using SAP CPI Tools Extension; the only difference is that the project is created from trace details in the Design iFlow section.
You need to activate the trace and run the iFlow.
After running the iFlow, press the Message button and then the Draw button to display all executed steps.
Double-click the Groovy script step, then click the VSCode Debug button. This will create a project containing the code from that step and add trace files for Headers, Properties, and Body.
To run or debug the project for the first time, it asks if you want to create a config.json file. This file is necessary because it contains the debug information.
It created a file.
After that, you can run or debug the code.
A print statement was added to display output in the console."
Create a properties file in the in folder.
RUN
When the run is finished, the result is in the out folder
DEBUG
Add breakpoints on lines 7, 12, and 15
The variables are shown on the left side
Line 7
Line 12
Line 15
Ready to streamline your Groovy debugging process? Give the VS Code extension a try and see how it can simplify your development workflow. If you have questions or want to share your experience, feel free to leave a comment below! Happy coding!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 30 | |
| 22 | |
| 19 | |
| 18 | |
| 15 | |
| 12 | |
| 11 | |
| 11 | |
| 9 | |
| 7 |