gpt4 book ai didi

java - 以编程方式关闭 Eclipse 应用程序

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:19:26 24 4
gpt4 key购买 nike

我有一个要关闭的 Eclipse 应用程序。问题是它是一个 headless 应用程序,所以我不能使用以下方法:

PlatformUI.getWorkbench().close();

我可以使用什么替代方法彻底关闭应用程序?

我的主要插件,即定义产品和应用程序的插件,包含以下依赖项:

  • org.eclipse.core.runtime

就是这样。

我使用扩展点:

  • org.eclipse.core.runtime.applications

定义我的应用。

我为它创建了一个 Swing UI,我希望能够在某个过程完成后或作为用户操作的结果关闭应用程序。我想知道 Eclipse 中是否有任何 API 可以执行此操作,或者在这种情况下我自己处理 UI,我是否必须通过退出实现 IApplication 的类来关闭应用程序。

最佳答案

可能正在使用 ResourcesPlugin服务?

参见 this class stop 方法的一个例子(我知道它是一个 AbstractUI 类,但它基本上是一个 Plugin ,如果你有这样一个派生自 Plugin 的类,你可以实现 org.osgi.framework.BundleActivator#stop 方法。

/**
* Shuts down this plug-in and discards all plug-in state.
*
* @exception CoreException
* If this method fails to shut down this plug-in.
*
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public final void stop(BundleContext context) throws Exception {
try {

/* Unregister as a save participant */
if (ResourcesPlugin.getWorkspace() != null) {
ResourcesPlugin.getWorkspace().removeSaveParticipant(this);
}

} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR,
getSymbolicName(), CommonUIStatusCodes.PLUGIN_SHUTDOWN_FAILURE,
getShutdownErrorMessage(getPluginName()), e));
} finally {
super.stop(context);
}
}

(显然,不要使用 CommonUIStatusCodes)

关于java - 以编程方式关闭 Eclipse 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2809592/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com