[英]How to run a command when the eclipse plugin is clicked?
I have a Plug-in Project in my Eclipse workspace. 我的Eclipse工作区中有一个插件项目。 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.
当我右键单击该项目并单击“以Eclipse应用程序运行”时,将打开另一个Eclipse实例,并且插件已成功安装。 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. 但是,当我导出项目时,创建jar并将jar放在plugins文件夹下,我能够看到plugin按钮,但是当我单击它时,应用程序无法打开。
Below, I show the java class that is being executed: 下面,我显示了正在执行的java类:
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: plugin.xml文件如下:
<?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="&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. 单击该按钮后,它必须运行一个可执行jar。 This is not happening when the plugin jar is placed in plugins folder.
将插件jar放在plugins文件夹中时不会发生这种情况。 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
. 问题是您的JAR文件
webspy/lib/abc.jar
没有包含在导出的插件com.example.eclipse.plugin
。 For this reason, when you click the button, the application is not opened (because the JAR file cannot be found). 因此,当您单击按钮时,不会打开应用程序(因为找不到JAR文件)。 Check the Error Log (Window -> Show View -> Error Log) and you will see an
Unhandled event loop exception
. 检查错误日志(窗口->显示视图->错误日志),您将看到
Unhandled event loop exception
。
To solve this issue, you must explicitly state that the abc.jar
file is included in your exported plug-in. 要解决此问题,您必须明确声明导出的插件中包含
abc.jar
文件。 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. 可以通过选中
abc.jar
文件的复选框在build.properties文件中(特别是在“ 二进制生成”部分中)完成abc.jar
操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.