How to debug Java application from Sublime Text editor
Asked Answered
G

2

8

Sometimes I am doing simple fixes for rather huge Java application and I don't want to open Eclipse for this task. Eclipse starts long and since the project is build out of large number of subprojects, which are build anyway by Maven, it takes ages before Eclipse is usable (at least ages in impatient Java developer scale).

Almost everything I need can be done in Sublime Text editor, however one place where Eclipse shines is debugger. My workflow is: make a fix, then test it running application (on server) using debugger, to check if everything is ok.

So is there any Sublime plugin, or other non-IDE solution for easy debugging of Java application.

Note: I have seen this post - its pretty old, maybe there is something better.

Gev answered 19/4, 2012 at 11:57 Comment(0)
L
3

You could look for a standalone Java Debugger like JDebugTool.

Or you could simply create an additional Eclipse workspace with only the bare minimal you need for remote debugging your application (just one project with all the source jars linked in). This workspace will start considerably faster than the full blown.

I have never worked with a standalone debugger for Java and personally I tend to keep the number of tools I have to learn as low as possible and Eclipse's debugger is pretty good.

Labanna answered 23/8, 2012 at 13:41 Comment(1)
The link is broken now.Killigrew
G
0

JDebug - A Java Debugging plugin for Sublime Text Debugging is a painful art. The programmers(coders) know about it. Even perfectly written code may misbehave sometimes and it is difficult to identify the piece of code causing the issue just by log statements. So the only possible way to identify the issue is to do step by step debugging of the code dynamically. There are so many debugging tools available for Java, some are standalone and few are integrated within the IDE like Eclipse. In this article, I will show you how to debug java codes remotely using JDebug in Sublime Text.

Setting up Sublime Text JDebug plugin can be installed using Package Control or manually. I will show you how to install JDebug plugin using Package Control. If you haven’t install the Package Control, you can install packages by installing package control. Once you have the package control installed, you should start Sublime Text. Open up the command palette from the Preferences --> Package Control menu and search for “Install Package”.

Now you can search for any package you like. In our case, we are going to search for the package “JDebug”.

Setting up App Server (Weblogic/Tomcat/any other) in debug mode Pass -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 as JVM argument to server startup command. You can change the debug port from 8000 to anything you prefer. Tomcat Add/update the JAVA_OPTS env variable in catalina.bat or catalina.sh set JAVA_OPTS=%JAVA_OPTS% -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 Weblogic Add/update the SAVE_JAVA_OPTIONS env variable in catalina.bat or catalina.sh set SAVE_JAVA_OPTIONS=%JAVA_OPTIONS% -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000

Setting up JDebug Setting up JDebug is very simple as it has only few settings to start with. You can copy and paste the default settings into user settings and update the following settings based on your environment.

workingdir - You need to set your current project directory like c:/worksapce/TestService (Windows) or /home/user/abc/workspace/TestService (Linux or Ubuntu) commandline - Set the jdb command with arguments. If JDK/bin is not in your environment PATH then you need to specify full path to the jdb command. Also change the hostname and port in which the java application service is running and listening. sourcepath - The path to the source file with in the project. For ant project it usually /src/ and for maven usually /src/main/java.

Breakpoints Ready to set the breakpoint?. Breakpoints are the way to inform the jvm to halt the execution at a particular point (line number or method in a class). When the execution halts, the application variables can be inspected. Add a breakpoint using 'Toggle Breakpoint' menu option from context menu. Context menu can be accessible using right click. A circle icon will be placed on the line number gutter when a breakpoint is added

When the jvm hits the breakpoint during the execution, the gutter icon will be changed to 'pointer' to indicate that the breakpoint is hit.

Inspect Variables Variables & expressions can be inspected using inline popup. Click on the variable or highlight the expression to evaluate/inspect inline.

Watch Expressions Expressions can be evaluated using the 'Add Expression' context menu. You can enter any valid expression to evaluate.

Enter the Expression

JDebug Variables It is interesting to watch the variables in the 'JDebug Variables' window. If a variable is complex object it will be displayed with '+' icon on gutter. These variables can be expanded further to get the additional details using 'Expand' context menu. The 'Expand' context menu will be enabled only in 'JDebug' variables window.

How to Continue? The application execution can be continued using one of the following menu options Step Over Continue execution to next line Step Into Continue the execution into a method call Step Out Step out of the current method and continue Continue Continue to next breakpoint or till completion enter image description here

Grisly answered 17/2, 2023 at 18:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.