我知道“不鼓励访问”应该是什么意思:你正在使用内部库,那些不在公共 API 中的东西,你根本不应该使用它。
现在,据我所知,“org.eclipse.osgi.util”包中的 EclipseStarter 类是公共 API 的一部分。我引用:
This package specifies API to start the platform.
Clients may use the EclipseStarter loader class to start the platform.
The EclipseStarter class is the only defined API in this package.
EclipseStarter 类的详细信息页面说明了这一点:
Special startup class for the Eclipse Platform. This class cannot be instantiated;
all functionality is provided by static methods.
Note that the fields on this class are not API.
我读到:方法可以使用吗?
我的代码:
import org.eclipse.core.runtime.adaptor.EclipseStarter;
这个已经给出警告“不鼓励访问:由于对所需库 [path-to-eclipse]\plugins\org.eclipse.osgi_3.7.2.v20120110-1415.jar 的限制,无法访问类型 EclipseStarter”
我使用该类的代码:
try {
EclipseStarter.shutdown();
EclipseStarter.startup(null, null);
} catch (Exception e) {
e.printStackTrace();
}
警告:不鼓励访问:由于对所需库 [path-to-eclipse]\plugins\org.eclipse.osgi_3.7.2.v20120110-1415.jar 的限制,无法访问类型 EclipseStarter
警告:不鼓励访问:由于对所需库 [path-to-eclipse]\plugins\org.eclipse.osgi_3.7.2.v20120110-1415.jar 的限制,无法访问 EclipseStarter 类型的方法 shutdown()
警告:不鼓励访问:由于对所需库 [path-to-eclipse]\plugins\org.eclipse.osgi_3.7.2.v20120110-1415 的限制,无法访问 EclipseStarter 类型的方法 startup(String[], Runnable)。罐
我知道,我现在正在使用可能不起作用的空值调用启动方法,但我现在只是在编写代码 - 尚未运行。我不喜欢这些警告。要么我完全错了(而且 EclipseStarter 不是公开的),要么我的配置中有问题......
我尝试调整类路径,以便插件依赖关系首先出现(在内部 JRE 之前),但这也不起作用。这些警告所谈论的库在依赖项中,而不是在我的 JRE 中。我不知道我还能尝试什么。
无论哪种方式,我实际上都在寻找一种以编程方式重新启动 Eclipse 的好方法。插件代码首先安装一些额外的插件(没有警告,用户也必须接受所有这些插件的许可协议),然后应该重新启动。PlatformUI.getWorkbench().restart();
直到现在我一直在使用,但这在重新启动日志时给了我一个错误(“事件循环”或其他东西)。
谁能指出我正确的方向?谢谢!
编辑:PlatformUI.getWorkbench().restart()
给我的错误如下:
eclipse.buildId=M20120208-0800
java.version=1.6.0_43
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=nl_BE
Framework arguments: -product org.eclipse.epp.package.rcp.product
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product
org.eclipse.epp.package.rcp.product
Error
Thu Nov 07 12:34:11 CET 2013
Unhandled event loop exception
org.eclipse.swt.SWTException: Widget is disposed
at org.eclipse.swt.SWT.error(SWT.java:4282)
at org.eclipse.swt.SWT.error(SWT.java:4197)
at org.eclipse.swt.SWT.error(SWT.java:4168)
at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340)
at org.eclipse.swt.widgets.Tree.getItems(Tree.java:3249)
at org.eclipse.jface.viewers.TreeViewer.getChildren(TreeViewer.java:171)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalCollectExpandedItems(AbstractTreeViewer.java:1588)
at org.eclipse.jface.viewers.AbstractTreeViewer.getExpandedElements(AbstractTreeViewer.java:1180)
at org.eclipse.ui.internal.dialogs.NewWizardNewPage.storeExpandedCategories(NewWizardNewPage.java:626)
at org.eclipse.ui.internal.dialogs.NewWizardNewPage.saveWidgetValues(NewWizardNewPage.java:544)
at org.eclipse.ui.internal.dialogs.NewWizardSelectionPage.saveWidgetValues(NewWizardSelectionPage.java:99)
at org.eclipse.ui.internal.dialogs.NewWizard.performFinish(NewWizard.java:128)
at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:831)
at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:432)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:624)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
at org.eclipse.jface.window.Window.open(Window.java:801)
at org.eclipse.ui.internal.handlers.WizardHandler$New.executeHandler(WizardHandler.java:257)
at org.eclipse.ui.internal.handlers.WizardHandler.execute(WizardHandler.java:277)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:293)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:241)
at org.eclipse.ui.internal.actions.CommandAction.runWithEvent(CommandAction.java:157)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
编辑2:我很确定发生上述错误是因为这段代码是错误的。我将如何编写 performFinish 代码以使该错误不会发生?与asyncExec
?
@Override
public final boolean performFinish() {
if (getContainer().getCurrentPage().equals(myLastPage)) {
PlatformUI.getWorkbench().restart();
return true;
} else {
return false;
}
}
编辑 3:好吧,我将 performFinish 代码更改为 use asyncExec
,但现在我收到此错误:
!ENTRY org.eclipse.ui 4 0 2013-11-07 13:56:21.380
!MESSAGE Unhandled event loop exception
!STACK 0
org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed)
at org.eclipse.swt.SWT.error(SWT.java:4282)
at org.eclipse.swt.SWT.error(SWT.java:4197)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4140)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: org.eclipse.swt.SWTException: Widget is disposed
at org.eclipse.swt.SWT.error(SWT.java:4282)
at org.eclipse.swt.SWT.error(SWT.java:4197)
at org.eclipse.swt.SWT.error(SWT.java:4168)
at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340)
at org.eclipse.swt.widgets.Text.setText(Text.java:1966)
at helper.CustomProgressMonitor$1.run(CustomProgressMonitor.java:64)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
... 23 more
这个返回了大约 50 次,所以很明显,当 Widget 已被释放时,他仍在尝试执行某些操作。
这是新performFinish
代码:
@Override
public final boolean performFinish() {
if (getContainer().getCurrentPage().equals(myLastPage)) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
PlatformUI.getWorkbench().restart();
}
});
return true;
} else {
return false;
}
}
只是为了完整:现在一切正常。还有另一个类(一个助手类),我没有在访问之前检查 Text-widget 是否已被释放。一旦解决了,这一切都将成为一种魅力。感谢greg-449!