我正在创建一个自定义的eclipse插件。
在为项目添加自然时,我遇到了这个例外:
org.eclipse.core.runtime.CoreException: Problems encountered while setting project description.
at org.eclipse.core.internal.resources.Project.setDescription(Project.java:1351)
at org.eclipse.core.internal.resources.Project.setDescription(Project.java:1378)
at projectwizard.ProjectWizardManager.createProjectNature(ProjectWizardManager.java:72)
at projectwizard.ProjectWizardManager.createProject(ProjectWizardManager.java:48)
at projectwizard.NewMobilePlatformProjectWizard.performFinish(NewMobilePlatformProjectWizard.java:40)
at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:827)
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:248)
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:4169)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
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:259)
at org.eclipse.ui.internal.handlers.WizardHandler.execute(WizardHandler.java:279)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:231)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:212)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:131)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:171)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.executeCommand(KeyBindingDispatcher.java:277)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.press(KeyBindingDispatcher.java:496)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.processKeyEvent(KeyBindingDispatcher.java:547)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.filterKeySequenceBindings(KeyBindingDispatcher.java:368)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.access$0(KeyBindingDispatcher.java:314)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher$KeyDownFilter.handleEvent(KeyBindingDispatcher.java:83)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1262)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1052)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1104)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1100)
at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1521)
at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:4640)
at org.eclipse.swt.widgets.Tree.WM_CHAR(Tree.java:5967)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4528)
at org.eclipse.swt.widgets.Tree.windowProc(Tree.java:5963)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4989)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2546)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3756)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1022)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:916)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:587)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:542)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
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:353)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Contains: Nature does not exist: com.mobile.platform.application.
这是我的plugin.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<extension
id="com.mobile.platform.plugin.newprojectwizrd"
point="org.eclipse.ui.newWizards" >
<category
id="eclipseplugin.com.mpp.ui.wizard" name="Mobile Platform">
</category>
<wizard
category="eclipseplugin.com.mpp.ui.wizard"
class="projectwizard.NewMobilePlatformProjectWizard"
icon="icons/applogo.png"
id="eclipseplugin.com.mpp.ui.wizard.NewApplicationWizard"
name="Mobile Platform Application"
project="true">
</wizard>
</extension>
<extension
id="com.mobile.platform.application"
point="org.eclipse.core.resources.natures">
<runtime>
<run
class="com.mobile.platform.plugin.ProjectNature">
</run>
</runtime>
</extension>
</plugin>
要在新创建的项目中添加自然,请输入以下代码:
private void createProjectNature(IProject project) throws CoreException {
if (!project.hasNature(ProjectNature.NATURE_ID)) {
IProjectDescription description = project.getDescription();
String[] prevNatures = description.getNatureIds();
String[] newNatures = new String[prevNatures.length + 1];
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
newNatures[prevNatures.length] = ProjectNature.NATURE_ID;
description.setNatureIds(newNatures);
project.setDescription(description, new NullProgressMonitor());
}
}
在创建项目性质时,它会执行project.setdescription,它会抛出异常,如上所述。
这是ProjectNature类:
public class ProjectNature implements IProjectNature {
public static final String NATURE_ID = "com.mobile.platform.application";
private IProject iProject;
@Override
public void configure() throws CoreException {
// TODO Auto-generated method stub
}
@Override
public void deconfigure() throws CoreException {
// TODO Auto-generated method stub
}
@Override
public IProject getProject() {
return iProject;
}
@Override
public void setProject(IProject project) {
// TODO Auto-generated method stub
this.iProject=project;
}
}
我没有得到这个缺失的东西。 请帮帮我。 提前谢谢。
答案 0 :(得分:1)
将扩展声明中的项目性质标识com.mobile.platform.application
重命名为例如mobileNature
:
<extension
id="mobileNature"
point="org.eclipse.core.resources.natures">
<runtime>
<run
class="com.mobile.platform.plugin.ProjectNature">
</run>
</runtime>
并相应地更新NATURE_ID
public class ProjectNature implements IProjectNature {
public static final String NATURE_ID = "com.mobile.platform.plugin.mobileNature";