How to show variable values when debug java in Eclipse? - java

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.

Related

How to avoid "Sharing is only supported for boot loader classes because bootstrap classpath has been appended" warning during debug with Java 11?

Recently I switched to the Java 11 and start to debug my app and saw this message:
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot
loader classes because bootstrap classpath has been appended
Found only this commit and ticket, but it doesn't tell me much.
Do I need to worry about it?
I had this issue too after installing jdk-12.0.1_windows-x64_bin.zip when trying to use the debugger with IntelliJ IDEA. I was getting an error of (Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended). I found, too, going into Setting and search for async and unchecking the Instrumenting agent box. Worked for me!
You can ignore this warning. It just means that class data sharing is disabled for classes not loaded by the bootstrap class loader.
From Improve Launch Times […] With Application Class-Data Sharing:
The JVM loads some of the JDK classes with the bootstrap class loader
and the rest with the system class loader, but includes all of them in
its default archive. When IntelliJ executes your project, it tells the
JVM to load some code with the bootstrap class loader by appending to
that class path (second part of the message). Now, that means that the
portion of the archive that contains classes loaded by the system
class loader is potentially invalidated and so the JVM partially
deactivates sharing (first part of the message).
You could disable class data sharing completely with -Xshare:off, but you would lose some performance.
I had this issue after installing Java12 when trying to use the debugger with Intellij Idea. The solution that I found was to go into Setting and searching for async and unchecking the Instrumenting agent box.
For me, the issue occurred only when I ran in Docker, and when I used a java command line agent like the DataDog APM agent (-javaagent:/dd-java-agent.jar).
When I ran in my JDK11 runtime environment (without the agent) I did not get the warnings.
For Intellij IDE -> Settings/Preferences dialog ( Ctrl+Alt+S ), go to Build | Execution | Deployment | Debugger | Async -> uncheck instrumenting agent
1.Open the Preferences option;
2.Find the Build,Execution,Deployment option;
3.Enter the Debugger --> Async Stack Traces ;
4.Uncheck the Instrumenting agent(requires debugger restart) ;
Please see this for detailed information.
Given this warning in IntelliJ is harmless (see https://stackoverflow.com/a/57957031/779173) you could just hide the line from your Console view by right-clicking on the line and selecting "Fold Lines Like This"
Having done this, you'll just see:
"C:\Program Files\Java\jdk-17.0.2\bin\java.exe" ... <1 internal line>
If it is not critical you can change your jdk version. I've changed from jdk14 to jdk 11. Hope it will work for you.
Got same problem, and tried to solve it as was written above.
But then i got another solution of problem without changing settings.
Press mouse right button on your file where you put break point and want to debug. Then choose "Debug ur file name.method()".
Don't use debug button from tools window. Seems the problem is that Idea can't understand which file u want to debug.
That worked for me without changing async settings.
Screenshot
Got the same problem, and tried to solve it as was written all the above methods.
But still, I wasn't able to debug my file the only reason is that before debugging your program you need to set debug point that till which point we want to debug. So just click on the place shown in the figure and set debug point then our program will debug easily. without doing anything else. enter image description here
Java version must be 9 or higher.
Today I found the same question as you.
Situation: debug while set no breakpoint
Solution: set at least one breakpoint before you click debug button!
You have to put the red dots at the left side of the code line you will make debug .
if not you get this massage on IntelliJ

Eclipse debugger hover produces empty box, no variable value

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.

Eclipse debug variable values don't 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 :

Watch expression doesnt show value in eclipse with java

I am using eclipse helio with java.
The watch expression option is not working for me when debugging my code
If I am doing a watch on variable, I cant see the value of that variable in the watch view
if i hoover with my mouse over the variable in the code i can see its value
if I check the variable in the variables view I can see its value
but in the watch expressions window i cant see its value (and its a problem if i try to watch expressions for example)
did anyone encounter this problem
(it used to work fine and show values but then suddenly it stopped and i have no idea why)
thanks
For me the problem had to do with a bad source path configuration for the project. There's a bunch of different ways to fix this, but one is to right-click on the thread while paused in the debugger, select "Edit Source Lookup...", and fiddle around with the paths specified there (see below).
In my case the problem was that I had specified the source lookup path as a "File System Directory". I was able to get my Expressions view working again by removing the "File System Directory" path and adding the source lookup as a "Java Project" instead.
You can check whether the problem is your source lookup path by opening the Debug -> Display view, and trying to evaluate a Java expression there. If you see a message like this, then your source lookup path is bad:
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.
Typically (at least for simple cases) the expression view works. But sometimes it indeed stops showing the values.
Usually refresh and clean of project + (sometimes) restart of eclipse help.
If you are able to see simple values and cannot see expression it sometimes because the class that is returned by expression does not appear in import list of current class. In this case I often try to write explicit cast to class into the watch expression and sometimes it helps.
Good luck.
In my case, while debugging against wildfly, my workspace somehow got corrupted after I opened as a maven project the sources of eclipselink 2.6.4.
After having open this maven project - that has all sort of dependencies you can image on oracle libraries - within my workspace the expressions and display view simply did not work any more. The variables view, while debugging continue to work as well as all the mouse overs.
I then created a fresh new empty worksapace.
Imported only the project I wanted to debug.
Reconfigured wildfly server.
And voila, expressions and display were back to work.
So, I have no idea what what happened to my eclipse... but it appears to be related to the metadata in my workspace being fundamentally broken.
Therefore, if you get the feeling that out of the blue lose the ability to properly debug in your workspace, it might be that your worksapce got hammered.
This appears to be what has happened to me. Finally, I am now back to being able to use the expressions on this new workspace.

How to debug Java application from Sublime Text editor

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

Categories