gpt4 book ai didi

Eclipse插件开发: Discouraged access: The type EclipseStarter is not accessible due to restriction on required library

转载 作者:行者123 更新时间:2023-12-02 04:45:46 25 4
gpt4 key购买 nike

我知道“不鼓励的访问”应该是什么意思:您正在使用内部库,那些不在公共(public) API 中的东西,您根本不应该使用它。

现在,据我所知,包“org.eclipse.osgi.util”中的类 EclipseStarter 是公共(public) 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.

来源:http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fosgi%2Futil%2Fpackage-summary.html

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 的限制,无法访问 EclipseStarter 类型的方法 startup(String[], Runnable) -1415.jar

我知道,我现在正在使用空值调用启动方法,这可能不起作用,但我现在只是在编写代码 - 尚未运行。我不喜欢这些警告。要么我在这方面完全错了(并且 EclipseStarter 不是公开的),要么我的配置中的某些地方是错误的...

我尝试调整类路径,使插件依赖项排在第一位(在内部 JRE 之前),但这也不起作用。这些警告所讨论的库在依赖项中,而不是在我的 JRE 中。我不知道我还能尝试什么。

不管怎样,归根结底,我实际上是在寻找一种以编程方式重新启动 Eclipse 的好方法。插件代码首先安装一些额外的插件(没有警告,用户也必须接受所有这些插件的许可协议(protocol)),然后应该重新启动。直到现在,我一直在使用 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 代码更改为使用 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;
}
}

补充一下:现在一切正常。还有另一个类(一个辅助类),我在访问它之前没有检查文本小部件是否已被处置。一旦解决了这一切,它就很有魅力了。感谢 greg-449!

最佳答案

PlatformUI.getWorkbench().restart(); 是正确的重启方式(除非您运行的是纯“e4”RCP)。您需要查看导致事件循环错误的原因。

包含 EclipseStarter 的包在 org.eclipse.osgi MANIFEST.MF 中标记为 x-friends="org .eclipse.core.runtime" 这意味着它仅供 org.eclipse.core.runtime 使用,所有其他插件将收到不鼓励的访问警告。

关于Eclipse插件开发: Discouraged access: The type EclipseStarter is not accessible due to restriction on required library,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19833551/

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