简体   繁体   English

Eclipse插件:将Java进程附加到代码启动

[英]Eclipse plugin: attach a java process to a code launch

So I am doing an eclipse plugin for educational purposes. 所以我正在做一个用于教育目的的eclipse插件。 My goal now is to have an additional java thread running , when the Run button is hit. 我现在的目标是在点击“运行”按钮时使另一个java线程运行。 So, alongside with the normally launched programme , I want to have my own plugin code running (which I specified in the plugin). 因此,除了正常启动的程序外,我还想运行自己的插件代码(在插件中指定)。

I thought about trying to create a new java thread , running my code when I execute DebugUITools.launch(config, mode); 我考虑过尝试创建一个新的Java线程,当我执行DebugUITools.launch(config, mode);时运行我的代码DebugUITools.launch(config, mode); . But I am not sure how I would attach the thread to the launched process so that I could stop the thread too... 但是我不确定如何将线程附加到启动的进程,以便也可以停止线程...

I also thought about creating java launch configuration for my plugin code, but it's probably impossible because as far as I can see, we need a Project for that. 我还考虑过为我的插件代码创建java启动配置,但这可能是不可能的,因为据我所知,我们需要一个Project

So, are there any possibilities to programmatically attach new threads to a launched program? 那么,是否有可能以编程方式将新线程附加到已启动的程序? Or maybe create a second launch configuration out of plugin code, and launch it? 还是用插件代码创建第二个启动配置,然后启动它?

I hope I was able to explain my struggle to you. 我希望我能向你解释我的挣扎。

Each Launch runs the code in a completely new JVM. 每次启动都在全新的JVM中运行代码。 You can't take a thread in the current JVM and move it to a different one. 您不能在当前JVM中使用线程并将其移至其他线程。

A second launch configuration in your code would only end up launching yet another JVM which doesn't get you anywhere. 您代码中的第二个启动配置只会最终启动另一个JVM,该JVM无法将您带到任何地方。

You would have the modify the existing launch configuration to add a jar containing your code and change the program entry point to point to your code so you can start your thread. 您将需要修改现有的启动配置,以添加一个包含您的代码的jar,并更改程序入口点以指向您的代码,以便您可以启动线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM