Monday, February 16, 2015

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 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.

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

54 comments:

  1. This is awesome. As always great work Senthil

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. You could give a real example of how to set up, I am newbie in using "Sublime Text"!
    I have only one working folder in c: \ JavaApp \. Alli am making practice and need to use jDebug to see how they change the values of the variables.
    Thank You.

    ReplyDelete
  4. Java developers will find this kit handy as it lets you test the compatibility of your projects with reference to Java specifications. Sun open-source, can now have access to their Compatibility Kit related to Java development technology.
    java

    ReplyDelete
    Replies
    1. I have read your blog its very attractive and impressive. I like it your blog.

      Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

      Java Online Training Java Online Training Core Java 8 Training in Chennai Java 8 Training in Chennai JavaEE Training in Chennai Java EE Training in Chennai

      Delete
  5. How do you determine the hostname and port in the commandline setting?

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Hibernate Online Training Hibernate Online Training Hibernate Training in Chennai Hibernate Training in Chennai Java Online Training Java Online Training

      Hibernate Training Institutes in ChennaiHibernate Training Institutes in Chennai Java Online Training Java Online Training

      Delete
  7. Hibernate and spring are the frameworks of Java. A java developer should be well aware of these frameworks in order to master the technology and work efficeiently.
    spring training in chennai | hibernate training in chennai
    FITA Academy reviews

    ReplyDelete
  8. Java is the most robust secured and multi threaded programming language which is the reason why most the the developers go for java. A single java code can be used for various platforms.
    JAVA training in chennai | java training institutes in chennai | FITA Academy Chennai

    ReplyDelete
  9. The best thing about HTML5 is that it allows the developers to embed the video files, audio files, and high quality graphics without any third party applications.
    html5 training in chennai | html5 training institutes in chennai | FITA Academy reviews

    ReplyDelete
  10. Hi, actually I'am new to angularJs and infact I'am learning angularjs with online training. I'am having doubt, if you could solve the doubt for me that would be very helpful. The doubt is, how can I reset a “$timeout”, and disable a “$watch()”?
    Regards,
    angularjs training in Chennai | angularjs training | angularjs training Chennai

    ReplyDelete
  11. The main thing which i like about web designing is that it needs creativity and we need to work differently acccording to our clients need this needs a creativity and innovation.
    web designing course in chennai | web designing training in chennai | web designing courses in chennai

    ReplyDelete
  12. Oracle database management system is a very secure and reliable platform for storing database and secured information.Due its reliable and trustworthy factor oracle DBA is famous all around the globe and is prefered by many large MNC which are using database management system.
    oracle training in Chennai | oracle dba training in chennai | oracle training institutes in chennai

    ReplyDelete
  13. I really similar to my spouse and i have bookmarked the internet blog. The item seems to be able to possibly be very interesting. it is advisable to keep uploading added with future with regard to all involving us. Contact Page

    ReplyDelete
  14. Spring is an open source framework which is mainly used in java applications that can be deployed in standalone platform.
    spring training in chennai | spring course in chennai

    ReplyDelete
  15. Excellent post. Keep sharing such a useful post.

    SEO Services in Chennai

    ReplyDelete
  16. The blog you presented was very nice and interesting which helped me to get update on the recent technologies.
    Angularjs training in chennai | Angularjs course in Chennai

    ReplyDelete
  17. Really cool post, highly informative and professionally written and I am glad to be a visitor of this perfect blog, thank you for this rare info! , Regards, servicenow training in hyderabad

    ReplyDelete
  18. Your blog content is really very informative and unique. Thanks for sharing the valuable blog. Core Java Training | Dot Net Training

    ReplyDelete
  19. Sublime Text and setting up its break up point is really a dedious one to go through, You made it simple to understand. Thanks for the post. Good Work
    AngularJS Training Institute in Chennai | Best AngularJS Training in Chennai | AngularJS training and placement

    ReplyDelete
  20. how can i determine the hostname and port for commandline?

    ReplyDelete
    Replies
    1. The hostname is where your application server like tomcat, jboss, weblogic or webshpere is running. The port is specify as debug port in the application server startup command

      Delete
  21. Much obliged to you for magnificent data I was looking for this information for my main goal.
    Regards,AngularJS Training in Chennai

    ReplyDelete
  22. Nice information about java debugging plugin Thanks for sharing it
    Java Training in Chennai

    ReplyDelete
  23. This article provides the information about Java its key features and scope for java professionals. This information is really helpful me to know more about Java programming language. Java Training in Chennai | Java Training | Java Course in Chennai

    ReplyDelete
  24. This is my first visit to your blog, your post made productive reading, thank you. Java Training in Chennai

    ReplyDelete
  25. Attractive blog post! I should read from some useful news for this blog section, It 's a great content Keep it useful sharing.
    Selenium Training in Chennai
    selenium training institute in chennai
    best angularjs training in chennai
    angularjs training institute in chennai

    ReplyDelete
  26. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharng this information,this is useful to me...
    Android training in chennai
    Ios training in chennai

    ReplyDelete
  27. Really it was an awesome article...very interesting to read..You have provided an nice article....Thanks for sharing..
    Web Design Company
    Web Development Company

    ReplyDelete
  28. Great blog.you put Good stuff.All the topics were explained briefly.so quickly understand for me.I am waiting for your next fantastic blog


    Core Java Online Training

    ReplyDelete
  29. Really very informative post you shared here. Keep sharing this type of informative blog. If anyone wants to become a Java professional learn Java Training in Bangalore. Nowadays Java has tons of job opportunities for all professionals.

    ReplyDelete
  30. I believe I set it up all correctly, and I can see the program waiting for the me to take the next step or release the breakpoint, but I never get the 'arrow icon' on my breakpoint through sublime.
    If I tell JDebug to stop debugging the program continues happily. Can somebody help me out?

    ReplyDelete
  31. This article provides the information about Java its key features and scope for java professionals. This information is really helpful me to know more about Java programming language. Anybody want to build your own website

    White Label Website Builder

    ReplyDelete
  32. Thanks for your informative blog!!! Your article helped me to understand the future of Core Java programming language. Keep on updating your with such awesome information.

    White Label Website Builder

    ReplyDelete
  33. SV Soft Solutions is offering best Java online training with 100% job assistance and high quality training facilities and well expert faculty .
    to Register you free demo please visit Java Online Training Institute with Job Support

    ReplyDelete
  34. If you are looking for spring hibernate training institute in chennai then candid training is the best place to learn.

    Candid gives you best in class spring hibernate training with high quality and post training support, We provide you free demo session and candid promises the permanent trainer throughout your session and focus on more practical.

    candid training

    ReplyDelete
  35. I'm trying to setup Jdebugger with Grails project. Jdebug says that jdb is attached, but Grails keeps waiting for more commands (a 'run' maybe?). Can you give any help for Grails setup? I've set following with no success:

    {
    "workingdir": "Code/git/project/",
    "commandline": "jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=5005 -launch",
    "sourcepath": "/target/work/",
    "debug": true
    }

    ReplyDelete
    Replies
    1. Hi Niko

      My settings are below and using Windows OS. TestService is my project directory which has the 'src' directory. You need to specify the base working directory and source_path_prefix if you have any.

      "workingdir": "C:/Workspace/TestService",
      "source_path_prefix": "/src/",

      In simple workingdir + source_path_prefix should point to the path where you have the java file or base package name

      My Project Structure (Windows)
      C:\
      .......Workspace
      ............TestService
      ..................src
      ......................com
      ...........................jdebug
      .................................demo
      ......................................servlet
      ............................................JDebugTestServlet.java

      Delete
    2. Thanks for helping. I still cannot get it to work. If I start my Grails app with grails 'run-app --debug-fork', it waits for jdb to connect. When I connect jdb using 'jdb -attach 5005' or 'jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=5005', the grails app continues and I can start using jdb aswell - All good! However, if I set those same commands to Jdebug commandline-config, the grails app keeps waiting for something. Jdebug continue-command in command menu is passive. In Jdebug console it says

      ## Attaching JDB... ##
      ## JDB Attached ##
      -> stop at ani.Code.git.bfw-forms.src.bfw-forms.grails-app.services.com.bcbmedical.bfw.forms.FormDataService.groovy:44

      Do you have any more ideas I could try to get it to work?

      Delete
  36. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.

    Best Java Training Institute Chennai


    Java Training Institute Bangalore


    ReplyDelete
  37. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…

    software testing course in chennai

    ReplyDelete
  38. Existing without the answers to the difficulties you’ve sorted out through this guide is a critical case, as well as the kind which could have badly affected my entire career if I had not discovered your website.
    big-data-hadoop-training-institute-in-bangalore

    ReplyDelete
  39. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.

    Hadoop Training in Chennai

    ReplyDelete
  40. Ciitnoida provides Core and java training institute in

    noida
    . We have a team of experienced Java professionals who help our students learn Java with the help of Live Base Projects. The object-

    oriented, java training in noida , class-based build

    of Java has made it one of most popular programming languages and the demand of professionals with certification in Advance Java training is at an

    all-time high not just in India but foreign countries too.

    By helping our students understand the fundamentals and Advance concepts of Java, we prepare them for a successful programming career. With over 13

    years of sound experience, we have successfully trained hundreds of students in Noida and have been able to turn ourselves into an institute for best

    Java training in Noida.

    java training institute in noida
    java training in noida
    best java training institute in noida
    java coaching in noida
    java institute in noida

    ReplyDelete