In Eclipse, if you run a program under "Debug" you can make changes to the code, and most of the time it will take effect immediately.
Sometimes, though, it will not -- in which case it pops up a message, or says "(may be out of sync)" next to the threads in the Debug pane.
What determines the kind of changes that can be hot-swapped? I've noticed these changes usually fail:
but sometimes it seems to be almost random. What is the logic behind determining whether code can be replaced or not?
Eclipse allows running an application in Debug mode which helps with stepping through each line of code in a program. Eclipse also provides a Debug Perspective which is a set of views grouped together that help inspect code and make the debugging process very effective.
A Java program can be debugged simply by right clicking on the Java editor class file from Package explorer. Select Debug As → Java Application or use the shortcut Alt + Shift + D, J instead.
The shortcut key to launch the previously launched Java application in the debug mode is F11. When a java program is started in the debug mode, users are prompted to switch to the debug perspective. The debug perspective offers additional views that can be used to troubleshoot an application.
To put breakpoints in your code, double click in the left margin on the line you want execution to stop on. You may alternatively put your cursor in this line and then press Shift + Ctrl + B . To control execution use the Step Into, Step Over and Step Return buttons. They have the shortcuts F5 , F6 and F7 respectively.
Method statements (procedural code) work. Everything related to adding, removing or changing class schemas does not work. So no modifying inheritances, fields, extracting methods, changing signatures etc.
Usually hot-swapping method statements does not work if you are doing anything forbidden at the same time. Then the hot-swapping connection is "broken", so to say.
One thing I do not know for sure is anonymous classes. Have never tried that in connection with hot-swapping.
Edit: The guys over there at zeroturnaround have compiled a list in their features section what the jvm debugger can not do out of the box to promote their product: http://www.zeroturnaround.com/jrebel/features/ . Whether you like the tool or not, the list reflects my experience.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With