[英]How to run a command when the eclipse plugin is clicked?
我的Eclipse工作區中有一個插件項目。 當我右鍵單擊該項目並單擊“以Eclipse應用程序運行”時,將打開另一個Eclipse實例,並且插件已成功安裝。 單擊插件按鈕后,將打開應用程序。
但是,當我導出項目時,創建jar並將jar放在plugins文件夾下,我能夠看到plugin按鈕,但是當我單擊它時,應用程序無法打開。
下面,我顯示了正在執行的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();
}
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>
單擊該按鈕后,它必須運行一個可執行jar。 將插件jar放在plugins文件夾中時不會發生這種情況。 請幫助我所缺少的。
問題是您的JAR文件webspy/lib/abc.jar
沒有包含在導出的插件com.example.eclipse.plugin
。 因此,當您單擊按鈕時,不會打開應用程序(因為找不到JAR文件)。 檢查錯誤日志(窗口->顯示視圖->錯誤日志),您將看到Unhandled event loop exception
。
要解決此問題,您必須明確聲明導出的插件中包含abc.jar
文件。 可以通過選中abc.jar
文件的復選框在build.properties文件中(特別是在“ 二進制生成”部分中)完成abc.jar
操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.