2

我正在开发一个 Eclipse 插件。在我的插件中,我有以下代码:

Bundle bundle = Platform.getBundle("org.eclipse.acceleo.EcoreDiff2EDelta");
URL fileURL = bundle.getEntry("src/metamodel/EcoreDiff.ecore");
String uri = null;
try {
        uri = FileLocator.resolve(fileURL).getFile();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    Resource resource = resourceSet.getResource(URI.createURI(uri), true);

此代码访问位于我的插件中的 src/metamodel 文件夹中的资源 (EcoreDiff.ecore)。当我通过右键单击项目文件夹-> 运行方式-> eclipse 应用程序运行插件时,一切正常。但是,如果我将插件导出为“可部署插件和片段”,我会得到下面的堆栈跟踪,这基本上意味着它找不到 EcoreDiff.ecore 文件。这两天我一直在尝试解决这个问题,我不明白这是怎么回事......

java.lang.reflect.InvocationTargetException
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:421)
at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:507)
at org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog.run(ProgressMonitorJobsDialog.java:275)
at org.eclipse.ui.internal.progress.ProgressManager$3.run(ProgressManager.java:960)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.progress.ProgressManager.busyCursorWhile(ProgressManager.java:995)
at org.eclipse.ui.internal.progress.ProgressManager.busyCursorWhile(ProgressManager.java:970)
at org.eclipse.ui.internal.progress.ProgressManager.run(ProgressManager.java:1166)
at org.eclipse.acceleo.EcoreDiff2EDelta.ui.popupMenus.AcceleoGenerateEcoreDiff2EDeltaAction.run(AcceleoGenerateEcoreDiff2EDeltaAction.java:91)
at org.eclipse.ui.actions.ActionDelegate.runWithEvent(ActionDelegate.java:70)
at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:241)
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:4169)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
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:585)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:540)
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(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: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)
Caused by: java.lang.NullPointerException
at org.eclipse.core.internal.runtime.Activator.getURLConverter(Activator.java:321)
at org.eclipse.core.runtime.FileLocator.resolve(FileLocator.java:227)
at org.eclipse.acceleo.EcoreDiff2EDelta.main.Generate.registerPackages(Generate.java:359)
at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.initialize(AbstractAcceleoGenerator.java:422)
at org.eclipse.acceleo.EcoreDiff2EDelta.main.Generate.<init>(Generate.java:97)
at org.eclipse.acceleo.EcoreDiff2EDelta.ui.common.GenerateAll.doGenerate(GenerateAll.java:90)
at org.eclipse.acceleo.EcoreDiff2EDelta.ui.popupMenus.AcceleoGenerateEcoreDiff2EDeltaAction$1.run(AcceleoGenerateEcoreDiff2EDeltaAction.java:76)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Root exception:
java.lang.NullPointerException
at org.eclipse.core.internal.runtime.Activator.getURLConverter(Activator.java:321)
at org.eclipse.core.runtime.FileLocator.resolve(FileLocator.java:227)
at org.eclipse.acceleo.EcoreDiff2EDelta.main.Generate.registerPackages(Generate.java:359)
at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.initialize(AbstractAcceleoGenerator.java:422)
at org.eclipse.acceleo.EcoreDiff2EDelta.main.Generate.<init>(Generate.java:97)
at org.eclipse.acceleo.EcoreDiff2EDelta.ui.common.GenerateAll.doGenerate(GenerateAll.java:90)
at org.eclipse.acceleo.EcoreDiff2EDelta.ui.popupMenus.AcceleoGenerateEcoreDiff2EDeltaAction$1.run(AcceleoGenerateEcoreDiff2EDeltaAction.java:76)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
4

1 回答 1

3

在您部署的插件中,“元模型”应该是 jar 根目录中的一个文件夹,如果它在您的 build.properties 中指定的话。如果你在罐子里看,它在那里吗?

然后尝试:

URL url = bundle.getEntry("metamodel/EcoreDiff.ecore");
URL fileURL = org.eclipse.core.runtime.FileLocator.toFileURL(URL);
于 2012-08-29T20:15:26.240 回答