Remote debugging is a very useful tool for web developers, both in frontend and backend. With remote debugging assuring your code works properly and finding flaws becomes more fluent and easier. Here you’ll find a quick guide to do remote debugging using IntelliJ Idea IDE.
As part of my training in the Nearsoft Academy I was tasked with coding solutions for an Open Source project. It’s a very intimidating thing to dive into a project and compete with other people around the globe with a solution.
It was an enriching experience, the open source community is very attentive. The lesson I learned from interacting with other developers was knowledge of invaluable tools for developing, debugging and even reading code.
Here’s what you need to know about debugging.
Your IDE Matters
The first IDE I used to read and write code was Visual Studio Code (VSC). It’s the one I got used to due to its simplicity and the extensions I was already familiar with. The project I was working on is called “Strongbox,” which ran with Maven and Springboot. It was a problem I’ve never faced before: debugging a service running remotely.
My first instinct was to set some breakpoints and then run the app just to see the values of the Java variables. The answers didn’t come. I took my sweet time trying to figure out why the app wasn’t stopping at the breakpoints until I decided to report my progress and blockers to the community.
They assisted me incredibly fast and were super cool with me. When I presented the problem to the community the first thing they told me was, “wrong IDE to begin from there 😃.” More than one person recommended IntelliJ Idea.
The reason VSC can’t debug as well ad IntelliJ Idea is that the latter was built specifically for Java coding. I no longer had to worry if my IDE had the right features or being limited by the lack of them. Which brings me to this advice,
Use the right tool for the job
I’m going to assume that you have already debugged a java project and that you are familiar with breakpoints and the notion of what debugging is. If you don’t know the meaning of these concepts don’t fret, here’s a quick tutorial
Remote debugging is very useful when you want to identify issues you can’t reproduce locally. To do this you have to run your instance in another pc. This kind of debugging is different because the application is running on a remote computer. Which means that you have a port open that your debugging tool, in this case IntelliJ, can connect to.
It wasn’t until I was told by one of my peers that remote debugging existed that I understood. My app was running with Maven with the ‘mvn spring-boot:run’ command, which effectively runs the app. But it doesn’t set a debugging port.
To set a debugging port it is necessary to run the app as ‘mvnDebug spring-boot:run’. All that was left was to enter the debugging configurations on IntelliJ Idea and click on run as debugger.
Configuring the Remote Port
Click on Run Configurations in the top right corner.
In IntelliJ Idea the process goes like this,
Click on the plus sign and select Remote to add a new configuration for a remote app we are going to debug.
Enter a name for your configuration and the port in which your app is running in debug mode.
Knowing the port in which the app will be running the debug mode is important. In Maven, the command ‘mvnDebug spring-boot:run’ runs on the port 8000. Now we just need to write 8000 on the port input and the address where we’re hosting our app.
We are done. Accept the configuration and run the Maven app on debug mode followed by the IDE.
Intellij Idea is not the only debugger. There are a lot of debugging tools out there, and a lot of them can do remote debugging too. Tools that help you debug by setting up watchers, evaluate expressions, remote debugging, drop frames, navigate suspended programs, and the list goes on.
There are two main takeaways from this,
- Using the right tool for the right job will make debugging and understanding the flow of an app much easier.
- Participating in Open Source projects can teach you a lot. It would’ve probably taken me a lot more time to be in contact with so many new concepts and tools.
Take a deep dive into the Open Source world, the worst that could possibly happen is that you’ll learn a lot more.
Any questions? Send me a line at [email protected].