在导出时使用Eclipse插件提供可执行文件

时间:2017-04-05 15:59:40

标签: java eclipse eclipse-plugin

我正在编写一个Eclipse插件,它使用可执行文件来执行某些任务。到现在为止,我的可执行文件驻留在我系统上的某个文件夹中。现在我正在导出插件,我还需要提供可执行文件,并在不同的机器上运行它们。

一些研究告诉我,我应该在插件项目中创建一个额外的文件夹,并将可执行文件放入其中。然后,一些代码将在运行插件时将可执行文件提取到临时位置。根据建议,我创建了一个名为“executables”的附加文件夹,并将我的可执行文件放入其中。我正在尝试使用以下代码,从SO本身复制:

Bundle bundle = Platform.getBundle("plugin id");
URL url = FileLocator.find(bundle, new Path("relative path to program"), null);
url = FileLocator.toFileURL(url);

此代码由 greg-449 提供,以回答此问题:Run program.exe from eclipse plugin project

关于上面的代码,我想知道以下事项:

  1. 什么是插件ID?它是插件清单文件的概述页面上显示的ID吗?

  2. 什么是“程序的相对路径”?在我的情况下,它应该是/executables/program.o?

  3. 按照上面的步骤,然后在Eclipse中安装插件,当我尝试运行命令时,给我未处理的循环异常

    以下是该计划:

    public class SampleHandler extends AbstractHandler {
    
    public SampleHandler() {
    }
    
    
    public Object execute(ExecutionEvent event) throws ExecutionException {
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
        Bundle bundle = Platform.getBundle("Sample");
        URL url = FileLocator.find(bundle, new Path("/lib/bandWidth.out"), null);
        try {
            url = FileLocator.toFileURL(url);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println(url.toString());
        return null;
    }
    

    }

    我只是使用此代码测试上面的代码段。这个输出是(没有安装插件):

    file:/usr/local/cuda-8.0/libnsight/../../../../home/limafoxtrottango/cuda-workspace/Sample/lib/bandWidth.out
    

    以下是错误的完整堆栈跟踪:

    org.eclipse.e4.core.di.InjectionException: java.lang.NullPointerException
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:62)
    at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:247)
    at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:229)
    at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
    at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:149)
    at org.eclipse.core.commands.Command.executeWithChecks(Command.java:499)
    at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
    at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
    at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:825)
    at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:701)
    at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$6(HandledContributionItem.java:685)
    at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:613)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4454)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1388)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3799)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3409)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:636)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:579)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:135)
    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:498)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
    Caused by: java.lang.NullPointerException
    at org.eclipse.core.internal.runtime.Activator.getURLConverter(Activator.java:321)
    at org.eclipse.core.runtime.FileLocator.toFileURL(FileLocator.java:205)
    at sample.handlers.SampleHandler.execute(SampleHandler.java:39)
    at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:294)
    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:498)
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
    ... 38 more
    

    谢谢!

1 个答案:

答案 0 :(得分:0)

插件ID在“概览”标签上调用ID,在MANIFEST.MF中调用Bundle-SymbolicName

相对路径是相对于插件目录根目录的路径。

您必须在bin.includes文件的build.properties部分列出要包含在插件中的所有内容。在测试期间,如果缺少某些内容,则不会出现错误,这只会在构建和安装插件时显示。