100798
100798

Reputation: 231

Java set breakpoints programmatically

Is there any way to programmatically set breakpoints in Java?

Assume you have the filename with the source code line:

Test.java:123

How this can be done?

Upvotes: 10

Views: 9653

Answers (4)

Matthew Molloy
Matthew Molloy

Reputation: 1186

Most debuggers will let you break on an exception, so just create your own BreakpointException class, throw and immediately catch it. Have the debugger pause only on BreakpointException.

Upvotes: 0

ashraf mohammed
ashraf mohammed

Reputation: 1350

  • I had the same problem but with 10000 files of java which i wanted to search for some string and put breakpoints based on that search.
  • You can generate xml file containing all breakpoints you need.
  • How to get that xml file structure?? simply go to debug mode --> right click ->Export breakpoints->then save the file anywhere.open that file and see how it is constructed.

  • what i did that i searched all the files line by line and generated that xml file and imported it to eclipse.

-You may wonder that how you can loop through 10000 file line by line as it will take a lot of time,you are right but what i did to overcome this is by inserting all lines into indexed field on mysql db.

-I know your case is not that complex but i hope it gives you an idea.you may come with something even better.

Upvotes: 0

Laplie Anderson
Laplie Anderson

Reputation: 6429

The Eclipse IDE does not allow you to set a breakpoint from your java code.

However, it does allow you to set conditional breakpoints. With a conditional breakpoint, you can tell Eclipse to only break on a line after some Java expression evaluates to true. You can only tell it to break after some number of iterations. These modes should suffice for almost every usecase.

To enable a conditional breakpoint, right-click on a breakpoint and go to "Breakpoint properties".

Upvotes: 2

James Scriven
James Scriven

Reputation: 8134

Back in the days of VisualAge Jave, I did this with

DebugSupport.halt()

This is something that would have to be supported by the IDE, and would break if the IDE dependencies were not present. As fas I know there are no IDEs today that support this.

Upvotes: 1

Related Questions