运行 tycho eclipse 插件作为 Eclipse 应用程序
Run tycho eclipse plugin as Eclipse Application
我刚刚使用 tycho 创建了一个 eclipse 插件。我可以 运行 mvn clean install
到目前为止没有错误。
现在我想 运行 插件作为 Eclipse 应用程序(它基本上是一个构建器)。当我按 run as Eclipse Application
时,会出现第二个 eclipse 实例。当我在那里创建一个新项目并添加我的构建器时,eclipse 抛出这个异常:
org.eclipse.e4.core.di.InjectionException: org.eclipse.core.commands.ExecutionException: Failed to toggle nature
Caused by: org.eclipse.core.commands.ExecutionException: Failed to toggle nature
Caused by: org.eclipse.core.runtime.CoreException: Problems encountered while setting project description
该方法出现错误:
private void toggleNature(IProject project) throws CoreException {
IProjectDescription description = project.getDescription();
String[] natures = description.getNatureIds();
for (int i = 0; i < natures.length; ++i) {
if (SidecarNature.NATURE_ID.equals(natures[i])) {
// Remove the nature
String[] newNatures = new String[natures.length - 1];
System.arraycopy(natures, 0, newNatures, 0, i);
System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1);
description.setNatureIds(newNatures);
project.setDescription(description, null);
return;
}
}
// Add the nature
String[] newNatures = new String[natures.length + 1];
System.arraycopy(natures, 0, newNatures, 0, natures.length);
newNatures[natures.length] = SidecarNature.NATURE_ID;
description.setNatureIds(newNatures);
// ---------------------------------------
// The Error is thrown here
// ---------------------------------------
project.setDescription(description, null);
}
我不知道哪里出了问题,因为这是 eclipse 模板代码。我没有改变任何东西。当我不使用 maven 时它应该可以工作。
这基本上就是pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tycho_example</groupId>
<artifactId>com.codeandme.tycho.plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<properties>
<tycho.version>0.23.0</tycho.version>
</properties>
<repositories>
<!-- add Mars repository to resolve dependencies -->
<repository>
<id>Mars</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/mars/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<!-- enable tycho build extension -->
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
编辑
这里要求的是完整的堆栈跟踪:
org.eclipse.e4.core.di.InjectionException: org.eclipse.core.commands.ExecutionException: Failed to toggle nature
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:68)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:252)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:234)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:152)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:493)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:486)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:799)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:675)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access(HandledContributionItem.java:659)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleEvent(HandledContributionItem.java:592)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4230)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1491)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1514)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1499)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1299)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4072)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3698)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1127)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
at org.eclipse.ui.internal.Workbench.run(Workbench.java:654)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Caused by: org.eclipse.core.commands.ExecutionException: Failed to toggle nature
at de.ustutt.sidewise.eclipseintegration.builder.AddRemoveSidewiseNatureHandler.execute(AddRemoveSidewiseNatureHandler.java:37)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:295)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
... 41 more
Caused by: org.eclipse.core.runtime.CoreException: Problems encountered while setting project description.
at org.eclipse.core.internal.resources.Project.setDescription(Project.java:1256)
at org.eclipse.core.internal.resources.Project.setDescription(Project.java:1281)
at de.ustutt.sidewise.eclipseintegration.builder.AddRemoveSidewiseNatureHandler.toggleNature(AddRemoveSidewiseNatureHandler.java:78)
at de.ustutt.sidewise.eclipseintegration.builder.AddRemoveSidewiseNatureHandler.execute(AddRemoveSidewiseNatureHandler.java:34)
... 48 more
编辑2
IStatus
:
Status WARNING: org.eclipse.core.resources code=568 Problems encountered while setting project description. null children=[[type: WARNING], [path: null], [message: Nature does not exist: eclipseintegration.builder.SidewiseNature.], [plugin: org.eclipse.core.resources], [exception: null]
]
IStatus Nature does not exist: eclipseintegration.builder.SidewiseNature.
中的消息说您正在尝试添加一个不存在的性质。
你用org.eclipse.core.resources.natures
扩展点声明了性质了吗?在那里声明的 id 是否匹配 SidecarNature.NATURE_ID
常量?
我刚刚使用 tycho 创建了一个 eclipse 插件。我可以 运行 mvn clean install
到目前为止没有错误。
现在我想 运行 插件作为 Eclipse 应用程序(它基本上是一个构建器)。当我按 run as Eclipse Application
时,会出现第二个 eclipse 实例。当我在那里创建一个新项目并添加我的构建器时,eclipse 抛出这个异常:
org.eclipse.e4.core.di.InjectionException: org.eclipse.core.commands.ExecutionException: Failed to toggle nature
Caused by: org.eclipse.core.commands.ExecutionException: Failed to toggle nature
Caused by: org.eclipse.core.runtime.CoreException: Problems encountered while setting project description
该方法出现错误:
private void toggleNature(IProject project) throws CoreException {
IProjectDescription description = project.getDescription();
String[] natures = description.getNatureIds();
for (int i = 0; i < natures.length; ++i) {
if (SidecarNature.NATURE_ID.equals(natures[i])) {
// Remove the nature
String[] newNatures = new String[natures.length - 1];
System.arraycopy(natures, 0, newNatures, 0, i);
System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1);
description.setNatureIds(newNatures);
project.setDescription(description, null);
return;
}
}
// Add the nature
String[] newNatures = new String[natures.length + 1];
System.arraycopy(natures, 0, newNatures, 0, natures.length);
newNatures[natures.length] = SidecarNature.NATURE_ID;
description.setNatureIds(newNatures);
// ---------------------------------------
// The Error is thrown here
// ---------------------------------------
project.setDescription(description, null);
}
我不知道哪里出了问题,因为这是 eclipse 模板代码。我没有改变任何东西。当我不使用 maven 时它应该可以工作。
这基本上就是pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tycho_example</groupId>
<artifactId>com.codeandme.tycho.plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<properties>
<tycho.version>0.23.0</tycho.version>
</properties>
<repositories>
<!-- add Mars repository to resolve dependencies -->
<repository>
<id>Mars</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/mars/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<!-- enable tycho build extension -->
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
编辑 这里要求的是完整的堆栈跟踪:
org.eclipse.e4.core.di.InjectionException: org.eclipse.core.commands.ExecutionException: Failed to toggle nature
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:68)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:252)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:234)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:152)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:493)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:486)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:799)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:675)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access(HandledContributionItem.java:659)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleEvent(HandledContributionItem.java:592)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4230)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1491)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1514)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1499)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1299)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4072)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3698)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1127)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
at org.eclipse.ui.internal.Workbench.run(Workbench.java:654)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Caused by: org.eclipse.core.commands.ExecutionException: Failed to toggle nature
at de.ustutt.sidewise.eclipseintegration.builder.AddRemoveSidewiseNatureHandler.execute(AddRemoveSidewiseNatureHandler.java:37)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:295)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
... 41 more
Caused by: org.eclipse.core.runtime.CoreException: Problems encountered while setting project description.
at org.eclipse.core.internal.resources.Project.setDescription(Project.java:1256)
at org.eclipse.core.internal.resources.Project.setDescription(Project.java:1281)
at de.ustutt.sidewise.eclipseintegration.builder.AddRemoveSidewiseNatureHandler.toggleNature(AddRemoveSidewiseNatureHandler.java:78)
at de.ustutt.sidewise.eclipseintegration.builder.AddRemoveSidewiseNatureHandler.execute(AddRemoveSidewiseNatureHandler.java:34)
... 48 more
编辑2
IStatus
:
Status WARNING: org.eclipse.core.resources code=568 Problems encountered while setting project description. null children=[[type: WARNING], [path: null], [message: Nature does not exist: eclipseintegration.builder.SidewiseNature.], [plugin: org.eclipse.core.resources], [exception: null]
]
IStatus Nature does not exist: eclipseintegration.builder.SidewiseNature.
中的消息说您正在尝试添加一个不存在的性质。
你用org.eclipse.core.resources.natures
扩展点声明了性质了吗?在那里声明的 id 是否匹配 SidecarNature.NATURE_ID
常量?