简体   繁体   中英

How to run a command when the eclipse plugin is clicked?

I have a Plug-in Project in my Eclipse workspace. When I right click the project and click on 'Run as Eclipse Application', another Eclipse instance is opened and the plug-in is installed successfully. When the plug-in button is clicked, the application opens.

However, when I export the project, create the jar and place the jar under plugins folder, I'm able to see the plugin button, but when I click it, the application is not opening.

Below, I show the java class that is being executed:

Bundle bundle = Platform.getBundle("com.example.eclipse.plugin");
        URL url = FileLocator.find(bundle, new Path("webspy/lib/abc.jar"), null);
        File file=null;
        try {
            url = FileLocator.toFileURL(url);
            file = URIUtil.toFile(URIUtil.toURI(url));

            String[] str={"java", "-jar", file.getAbsolutePath()};
            ProcessBuilder pb = new ProcessBuilder(str);
            Process p = pb.start();
        } catch (URISyntaxException e1) {
            e1.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }

The plugin.xml file is the following:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

   <extension
         point="org.eclipse.ui.actionSets">
      <actionSet
            label="Sample Action Set"
            visible="true"
            id="com.example.eclipse.plugin.actionSet">
         <menu
               label="FEAT"
               id="sampleMenu">
            <separator
                  name="StartWebSpy">
            </separator>
         </menu>
         <action
               label="&amp;Start WebSpy"
               icon="icons/sample.gif"
               class="com.example.eclipse.plugin.actions.SampleAction"
               tooltip="Start WebSpy"
               menubarPath="sampleMenu/sampleGroup"
               toolbarPath="sampleGroup"
               id="com.example.eclipse.plugin.actions.SampleAction">
         </action>
      </actionSet>
   </extension>

</plugin>

It has to run an executable jar once the button is clicked. This is not happening when the plugin jar is placed in plugins folder. Please help what am I missing.

The problem is that your JAR file webspy/lib/abc.jar is not being included in your exported plug-in com.example.eclipse.plugin . For this reason, when you click the button, the application is not opened (because the JAR file cannot be found). Check the Error Log (Window -> Show View -> Error Log) and you will see an Unhandled event loop exception .

To solve this issue, you must explicitly state that the abc.jar file is included in your exported plug-in. This can be done in the build.properties file (in particular, in the Binary Build section) by checking the checkbox of the abc.jar file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM