Blog

VS Code BoxLang Extension: Debugging BoxLang in CommandBox

Maria Jose Herrera September 26, 2024

Spread the word

Maria Jose Herrera

September 26, 2024

Spread the word


Share your thoughts

Debugging a CommandBox BoxLang Server

So you’ve installed CommandBox and are running the latest BoxLang server like a boss. You open up your browser and are met with an error message. This looks like a job for, you guessed it, the BoxLang VS Code Debugger!

Hooking VS Code Up To Your Server

Connecting your debugger to an external my seem intimidating but CommandBox + VS Code makes this pretty straightforward.

Configuring CommandBox

To start we will need to make sure our server is configured properly. You can do this one of two ways.

We can add JVMArgs to the CLI

server start cfengine=boxlang javaVersion=openjdk21_jdk JVMArgs='-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8888'

The alternative approach is to add some configuration to our server.json.

{
  "JVM": {
    "args": "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8888",
    "javaVersion": "openjdk21_jdk"
  }
}

In these examples I’ve used port 8888 as the port we want the debugger to connect to control the CommandBox server through. You can specify whatever open port you want. You just need to make sure that you use the same one at every step.

Once you start your server it should run as normal.

Configuring VS Code

Now that your server is configured, we need to setup VS Code. We will need to update your .vscode/launch.json. If you don’t see this file, you can create it yourself and VS Code will pick it up.

We want the launch.json to look something like

{
  "configurations": [
    {
      "name": "Debug CommandBox",
      "type": "boxlang",
      "request": "attach",
       // make sure this is the same value you configured your server with            
      "serverPort": "8888"
    }
  ]
}

Starting a Debug Session

At this point your server is configured, it’s running, and you have just added a launch configuration. The next step is to run the debugger. All we need to do is open up the debug tab in our side-panel and select the correct configuration.

ContentBox

Now that we have everything setup all we need to do is press “play” or hit f5 and VS Code will fire up the BoxLang debugger and attach to your BoxLang server.

Conclusion

We’ve covered how easy it is to setup a BoxLang server and start debugging it with the BoxLang VS Code extension and CommandBox. Hopefully this will be a useful addition to your workflow.

Add Your Comment

Recent Entries

Top ColdFusion security vulnerabilities in 2024 and how to prevent them

Top ColdFusion security vulnerabilities in 2024 and how to prevent them

ColdFusion continues to be a powerful platform for web application development. However, with its widespread use, it's crucial to remain vigilant about potential security vulnerabilities. This article provides a technical overview of the most relevant security threats affecting ColdFusion (CFML or Adobe ColdFusion) in 2024 and offers practical steps to mitigate them.

1. SQL Injection Vulnerabilities SQL Injection remains one of the most common and dangerous vulnerabilities in C...

Cristobal Escobar
Cristobal Escobar
September 24, 2024
BoxLang 1.0.0 Beta 15 Launched

BoxLang 1.0.0 Beta 15 Launched

Welcome to Beta 15! This release brings several significant enhancements aimed at improving the efficiency and functionality of the CLI environment and continued bug fixing to bring our CFML compatibility to several client applications and Ortus Libraries. Key among these is the introduction of the bx-web-support module, which allows the CLI to interface with web server capabilities, making it an excellent tool for testing and feature auditing. Additionally, the merge capabilities within module settings have been refined to support deep merges from the configuration file, ensuring greater flexibility and control.

Luis Majano
Luis Majano
September 20, 2024
ColdBox Free Tip 1: Environment Variables In The Config

ColdBox Free Tip 1: Environment Variables In The Config

Welcome to the first of 10 FREE tips and tricks in our "102 ColdBox Tips and Tricks" Book! In this post, we’ll show you how to easily access system environment variables within your ColdBox configuration files, making your app setup smoother and more flexible!

Maria Jose Herrera
Maria Jose Herrera
September 19, 2024