gpt4 book ai didi

eclipse - 访问 Eclipse 可部署插件中的资源

转载 作者:行者123 更新时间:2023-12-04 05:34:41 25 4
gpt4 key购买 nike

我正在开发一个 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)

最佳答案

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

然后尝试:

URL url = bundle.getEntry("metamodel/EcoreDiff.ecore");
URL fileURL = org.eclipse.core.runtime.FileLocator.toFileURL(URL);

关于eclipse - 访问 Eclipse 可部署插件中的资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12107524/

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