且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Eclipse JDT以编程方式设置/创建断点

更新时间:2023-01-09 10:10:36

大多数Eclipse插件只能在Eclipse环境中运行,因为它们依赖于Eclipse / OSGi插件基础架构正确初始化



由于 JDIDebugModel.createLineBreakpoint 需要一个 IResource 对象,它只能在Eclipse IDE(或基于IDE的RCP)中使用工作区。



所以,是的,你可以在Eclipse插件必须安装到Eclipse或Eclipse RCP中。


I would like to programmatically set/create a breakpoint in another file at an arbitrary line number in Eclipse. I would love to see a generic solution, but I guess I have to rely on the Eclipse JDT plugin for it. How can I do that? I tried something like:

JDIDebugModel.createLineBreakpoint(resource, typeName, lineNumber, -1, -1, 0, false, null);

But I have two problems with it:

  1. I have to include a whole lot of libraries to my build path to make it work, e.g. /usr/local/eclipse/plugins/org.eclipse.core.resources_3.9.0.v20140514-1307.jar. If I add them, they require other ones etc. I probably have to add all Eclipse plugins/libraries to make it work.
  2. How do I get a proper resource in order to give it to the method above? Giving a null value will most probably not work. But all implementations of IResource are internal...

I also thought about directly communicating with the JDI, but I could not get it going in combination with the Eclipse debugger (here is a great, but german resource for it).

If it is not possible from arbitrary code, would it be possible from within an Eclipse plugin? This would also be an option, though not preferable.

I could not find any solution for it and hope to get some help here. Thanks in advance!

Most Eclipse plugins can only be run in the Eclipse environment because they rely on the Eclipse/OSGi plugin infrastructure being initialized properly.

Since JDIDebugModel.createLineBreakpoint requires an IResource object it can only be used in the Eclipse IDE (or an RCP based on the IDE) with a workspace.

So, yes, you can use this in a Eclipse plugin which would have to be installed in to Eclipse or an Eclipse RCP.