我正在使用eclipse plugin
,它将在启动时导入preferences(.epf)
。
我正在使用以下代码:
@Override
public void earlyStartup()
{
Display.getDefault().syncExec( new Runnable() {
@Override
public void run() {
try {
InputStream in = new FileInputStream(new File("D:/pref.epf"));
Platform.getPreferencesService ().importPreferences (in);
}
catch (Exception e) {
e.printStackTrace ();
}
}
});
}
但我收到以下错误:
java.lang.IllegalStateException:首选项节点 " org.eclipse.core.net"已被删除。在 org.eclipse.core.internal.preferences.EclipsePreferences.checkRemoved(EclipsePreferences.java:200) 在 org.eclipse.core.internal.preferences.EclipsePreferences.internalNode(EclipsePreferences.java:653) 在 org.eclipse.core.internal.preferences.EclipsePreferences.node(EclipsePreferences.java:812) 在 org.eclipse.core.internal.net.PreferenceManager.getBoolean(PreferenceManager.java:90) 在 org.eclipse.core.internal.net.ProxyManager.preferenceChange(ProxyManager.java:416) 在 org.eclipse.core.internal.preferences.EclipsePreferences $ 3.run(EclipsePreferences.java:896) 在org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)at org.eclipse.core.internal.preferences.EclipsePreferences.firePreferenceEvent(EclipsePreferences.java:899) 在 org.eclipse.core.internal.preferences.EclipsePreferences.remove(EclipsePreferences.java:1014) 在 org.eclipse.core.internal.preferences.EclipsePreferences.removeNode(EclipsePreferences.java:1027) 在 org.eclipse.core.internal.preferences.EclipsePreferences.removeNode(EclipsePreferences.java:1038) 在 org.eclipse.core.internal.preferences.EclipsePreferences.removeNode(EclipsePreferences.java:1038) 在 org.eclipse.core.internal.preferences.PreferencesService $ 1.访问(PreferencesService.java:140) 在 org.eclipse.core.internal.preferences.EclipsePreferences.accept(EclipsePreferences.java:146) 在 org.eclipse.core.internal.preferences.PreferencesService.applyPreferences(PreferencesService.java:196) 在 org.eclipse.core.internal.preferences.PreferencesService.importPreferences(PreferencesService.java:685) 在 com.gemalto.shd.eclipsebundle.StartupClass $ 1.run(StartupClass.java:133) 在 org.eclipse.ui.internal.UILockListener.doPendingWork(UILockListener.java:164) 在 org.eclipse.ui.internal.UISynchronizer $ 3.run(UISynchronizer.java:158) 在org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135) 在 org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4145) 在org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3762) 在 org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine $ 9.run(PartRenderingEngine.java:1113) 在 org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) 在 org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997) 在 org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:138) 在org.eclipse.ui.internal.Workbench $ 5.run(Workbench.java:610)at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) 在 org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:567) 在 org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150) 在 org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124) 在 org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) 在 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) 在 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) 在 org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354) 在 org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at java.lang.reflect.Method.invoke(未知来源)at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)at at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)at at org.eclipse.equinox.launcher.Main.run(Main.java:1450)at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
!ENTRY org.eclipse.equinox.preferences 4 2 2014-04-11 18:00:50.950 !MESSAGE从插件调用代码时出现问题: " org.eclipse.equinox.preferences&#34 ;. !堆栈0 java.lang.IllegalStateException:首选项节点 " org.eclipse.core.net"已被删除。在 org.eclipse.core.internal.preferences.EclipsePreferences.checkRemoved(EclipsePreferences.java:200) 在 org.eclipse.core.internal.preferences.EclipsePreferences.internalNode(EclipsePreferences.java:653) 在 org.eclipse.core.internal.preferences.EclipsePreferences.node(EclipsePreferences.java:812) 在 org.eclipse.core.internal.net.PreferenceManager.getBoolean(PreferenceManager.java:90) 在 org.eclipse.core.internal.net.ProxyManager.preferenceChange(ProxyManager.java:416) 在 org.eclipse.core.internal.preferences.EclipsePreferences $ 3.run(EclipsePreferences.java:896) 在org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)at org.eclipse.core.internal.preferences.EclipsePreferences.firePreferenceEvent(EclipsePreferences.java:899) 在 org.eclipse.core.internal.preferences.EclipsePreferences.remove(EclipsePreferences.java:1014) 在 org.eclipse.core.internal.preferences.EclipsePreferences.removeNode(EclipsePreferences.java:1027) 在 org.eclipse.core.internal.preferences.EclipsePreferences.removeNode(EclipsePreferences.java:1038) 在 org.eclipse.core.internal.preferences.EclipsePreferences.removeNode(EclipsePreferences.java:1038) 在 org.eclipse.core.internal.preferences.PreferencesService $ 1.访问(PreferencesService.java:140) 在 org.eclipse.core.internal.preferences.EclipsePreferences.accept(EclipsePreferences.java:146) 在 org.eclipse.core.internal.preferences.PreferencesService.applyPreferences(PreferencesService.java:196) 在 org.eclipse.core.internal.preferences.PreferencesService.importPreferences(PreferencesService.java:685) 在 com.gemalto.shd.eclipsebundle.StartupClass $ 1.run(StartupClass.java:133) 在 org.eclipse.ui.internal.UILockListener.doPendingWork(UILockListener.java:164) 在 org.eclipse.ui.internal.UISynchronizer $ 3.run(UISynchronizer.java:158) 在org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135) 在 org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4145) 在org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3762) 在 org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine $ 9.run(PartRenderingEngine.java:1113) 在 org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) 在 org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997) 在 org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:138) 在org.eclipse.ui.internal.Workbench $ 5.run(Workbench.java:610)at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) 在 org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:567) 在 org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150) 在 org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124) 在 org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) 在 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) 在 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) 在 org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354) 在 org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at java.lang.reflect.Method.invoke(未知来源)at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)at at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)at at org.eclipse.equinox.launcher.Main.run(Main.java:1450)at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
答案 0 :(得分:1)
查看导入首选项对话框我认为您需要在导入中指定首选项过滤器:
IPreferenceFilter [] filters = new IPreferenceFilter[1];
filters[0] = new IPreferenceFilter() {
public String[] getScopes() {
return new String[] {InstanceScope.SCOPE, ConfigurationScope.SCOPE};
}
public Map getMapping(String scope) {
return null;
}
};
IPreferencesService service = Platform.getPreferencesService();
IExportedPreferences prefs = service.readPreferences(input stream);
service.applyPreferences(prefs, filters);
(改编自org.eclipse.ui.internal.wizards.preferences.WizardPreferencesImportPage1
)