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.
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.
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
Related
I debug a simple java application on Eclipse in debug as and step into java resource bundle which got interrupted exception in line construction.getCause
How do I trace each variable and express to see the values from java library?
In j2ee, I can point mice at params, vars and assigned value from express, how do I see it in java application?
Why it cannot find the resource MyBundle base for MyBundle_zh.properties under project src?
Screen shot: https://plus.google.com/collection/UFuOlB
https://lh3.googleusercontent.com/ibrMgi8udPlaAIvyvPKc4tE5Agw5SzXxi5yp0a3yZJA5zNkYymSPgFHUEsO_tD2HsDMUZzE2=w640-h360-p-rw
Thanks
Eclipse has different Perspectives, you can switch them from Window -> Show Perspective. Each Perspective can have a different set of views. In you case, make sure that you have the Debug Perspective open and then (if you don't have it there already) do:
Window -> Show View -> Variables
Then, when your execution stops on a set breakpoint, you will be able to inspect all the relevant variables in the "Variables" view.
Your Installed JREs preference page, project Java Build Paths, and launch configurations should not be using "c:\Program Files\Java\jdk1.7.0_04\jre". They should instead just point to "c:\Program Files\Java\jdk1.7.0_04", after which the Java platform sources will be shown and debugging features you expect will work more automatically.
I'm debugging a PaxExam integration test in Eclipse. I'm currently stepping through the code for a class and method that I don't yet have the source for. When it hits the breakpoint, it says "Source not found" (with the "Edit Source Lookup Path" button), but when I visit the class file I know it's using, it's able to decompile it (using jd-eclipse).
(Note that running paxexam tests actually forks a process, so debugging them requires setting the "-Xdebug" parameters in the run configuration of the test class, and then using a "Remote Java Application" configuration to connect to it.)
While stepping through most of the code, I can enter expressions in the Display view, even with available completions, and display values and execute methods.
When it hits the breakpoint in the decompiled class (showing "Source not found" in the editor view), I can see the local and instance variables in the Variables pane. I can then switch to the view of the decompiled class and use the stack trace info to see what line I'm on.
At this point, if I try to enter any expression in the Display View and display it (even just "this"), it says:
Evaluation failed...To perform an evaluation, an expression must be
compiled in the context of a Java project's build path. The current
execution context is not associated with a Java project in the
workspace.
I'm trying to get access to the source code for this class, but I would think I wouldn't need to go to that point. Is there a reasonable workaround for this situation?
I wrote a sample java agent that creates a "hello world" file in a specific place. I want it to run whenever any java applet is run (definitely including ones I didn't write myself.) How do I do that?
My agent works when I run it manually from the command line (as in, running another java file with the agent attached to it.) On the automatic front, I tried going into the java configuration panel -> Java -> View -> JRE Configuration Settings -> setting the optional arguments to attach my agent, but that doesn't seem to do the trick. I browse with FF to someplace that makes me run a java applet but no file is created.
I'm guessing I'm missing something basic here, because when I try to google this people all around various forums seem to answer it as if it's the most trivial thing: "just use -javaagent, read more about it in this (link)."
If it helps at all, this is the optional parameter I add in the configuration panel (which works when I use it manually):
-javaagent:C:\Users\admin\workspace\poc\bin\poc\myagent.jar
Update: I found out I can set an environment variable (JAVA_TOOL_OPTIONS) to -javaagent:(agentpath). Once again it works flawlessly with local java applications, but now when I browse over to a webpage with an applet, firefox auto-closes itself. IE declares the webpage broken. Chrome doesn't even display the applet. The agent itself at this point does nothing - it just has an empty premain method. Anyone?
Setting the environment variable JAVA_TOOLS_OPTIONS=-javagent:(path) is right.
My error was that I misconstructed the .jar file. Once I fixed that (simply used the jar.exe tool to make my .jar) it worked properly - locally and on all applets via firefox. Until then, that was what caused firefox to either hang or crash when encountering an applet.
I'm debugging a Java (Android) application in Eclipse Indigo. In the debug perspective, if I'm stopped at a breakpoint, when I hover over a variable to see its value it displays a blank, white box (where I assume the variable's value is supposed to appear?) but with no content. It does not seem to matter what kind of a variable it is, local or class-scope, static or instance, the box is just as blank.
I can see the variables I need to see in the variables tab of the debugger perspective, but it would be a lot more convenient to see them by hovering.
In Preferences>Java>Editor>Hovers I've tried it with both Variable Values and Combined Hover with no improvement. I'm running on Windows 7, if that matters.
N.B. I have read this thread: Eclipse: Hover broken in debug perspective
Try to hit the restore defaults as described in Eclipse: Hover broken in debug perspective. Make sure to stop your debug run and restart.
You might also check Eclipse's Debug view documentation.
Try refactoring a package in your project then trying it again.
Could also be a bug
https://bugs.eclipse.org/bugs/show_bug.cgi?id=357127
Which version are you using?
I am seeing the same thing on Ubuntu. I am using the program VcXSrv on my Windows 10 system to get program windows from Ubuntu.
I had to turn off The 'Native opengl' option in the XLauncher when starting VcXSrv to get the hover text to appear.
I'm currently coding with Java in Eclipse, and I'm trying to use Eclipse's built in debugger to try and debug my code. However, once I enter debug mode and try to run the program till the breakpoint, the variables aren't showing up in the variable window. Any ideas?
Make sure you're not in the Breakpoints tab as opposed to the Variables tab on the top-right window in the Debug perspective. When in doubt, simply go to Window > Show View > Variables.
This is usually caused by a rendering bug in Eclipse. Often letting the application run past the breakpoint, then trying to re-run again to the breakpoint fixes the display. Other times you have to restart the IDE.
I just had a similar problem, I could only see method arguments and this members, but not local variables. I was searching in all possible project settings and found out this checkbox ("Add variable attributes to generated class files") wasn't checked. Make sure all 3 options (used by debugger) are on :