2012-08-14 104 views
1

我開發了一個簡單的插件來生成一些例程代碼。這個插件對Package Explorer的彈出菜單有貢獻。它從開發環境(Eclipse RCP的Launch as Eclipse application)運行時按預期工作 - 菜單中出現適當的菜單項,並且其調用符合預期。自定義Eclipse插件部署彈出包裝資源管理器

但是,我很難將其部署到不同的Eclipse實例中。

開發的插件與導出嚮導一起導出,導出嚮導生成一個單獨的jar文件。這個jar文件已被放入另一個Eclipse安裝的dropings目錄中(新打包的)。當這個Eclipse實例啓動時,Package Explorer的彈出菜單不包含提供的菜單項。來自Eclipse安裝詳細信息的信息顯示該插件存在於插件選項卡上,配置選項卡將其列爲tg.companion (1.0.0.201208132302) "Companion Object Generator" [Starting]

我錯過了什麼?爲什麼提供的菜單項不顯示?

Thanx。


locationURI的菜單貢獻popup:org.eclipse.jdt.ui.PackageExplorer,財產allPopupstrue

該插件是無符號的。


下面是可能會暴露一些光的插件文件。

的plugin.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<?eclipse version="3.4"?> 
<plugin> 
    <extension point="org.eclipse.ui.menus"> 
     <menuContribution 
      allPopups="true" 
      locationURI="popup:org.eclipse.jdt.ui.PackageExplorer"> 
     <command 
       commandId="tg.companion.handler.generator" 
       label="TG Create Companion Object" 
       style="push" 
       tooltip="Creates a companion object to the selected entity object, and provides DAO/RAO implementations"> 
     </command> 
     </menuContribution> 
    </extension> 
    <extension point="org.eclipse.ui.commands"> 
     <command 
      defaultHandler="tg.companion.handler.GenerateCompanionObjects" 
      id="tg.companion.handler.generator" 
      name="Generate Comanion"> 
     </command> 
    </extension> 
</plugin> 

MANIFEST.MF:

Manifest-Version: 1.0 
Bundle-ManifestVersion: 2 
Bundle-Name: Companion Object Generator 
Bundle-SymbolicName: tg.companion;singleton:=true 
Bundle-Version: 1.0.0.qualifier 
Bundle-Activator: tg.companion.Activator 
Bundle-Vendor: TG 
Require-Bundle: org.eclipse.ui, 
org.eclipse.core.runtime, 
org.eclipse.jdt.core;bundle-version="3.8.1", 
org.eclipse.core.resources;bundle-version="3.8.0", 
org.eclipse.core.expressions;bundle-version="3.4.400" 
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 
Bundle-ActivationPolicy: lazy 

命令處理程序:

package tg.companion.handler; 

import org.eclipse.core.commands.AbstractHandler; 
import org.eclipse.core.commands.ExecutionEvent; 
import org.eclipse.core.commands.ExecutionException; 
import org.eclipse.core.commands.IHandler; 
import org.eclipse.core.resources.IFolder; 
import org.eclipse.core.resources.IProject; 
import org.eclipse.jdt.core.ICompilationUnit; 
import org.eclipse.jdt.core.IJavaProject; 
import org.eclipse.jdt.core.IPackageFragment; 
import org.eclipse.jdt.core.IPackageFragmentRoot; 
import org.eclipse.jdt.core.IType; 
import org.eclipse.jdt.core.JavaCore; 
import org.eclipse.jdt.core.JavaModelException; 
import org.eclipse.jface.dialogs.MessageDialog; 
import org.eclipse.jface.viewers.ISelection; 
import org.eclipse.jface.viewers.IStructuredSelection; 
import org.eclipse.swt.widgets.Shell; 
import org.eclipse.ui.handlers.HandlerUtil; 

public class GenerateCompanionObjects extends AbstractHandler implements IHandler { 

    @Override 
    public Object execute(final ExecutionEvent event) throws ExecutionException { 
     final Shell shell = HandlerUtil.getActiveShell(event); 
     final ISelection sel = HandlerUtil.getActiveMenuSelection(event); 
     final IStructuredSelection selection = (IStructuredSelection) sel; 

     final Object firstElement = selection.getFirstElement(); 
     if (firstElement instanceof ICompilationUnit) { 
      createOutput(shell, (ICompilationUnit) firstElement); 
     } else { 
      MessageDialog.openWarning(shell, "Companion Object Generation Warning", "Please select an entity object for generating a corresponding companion."); 
     } 
     return null; 
    } 

    private void createOutput(final Shell shell, final ICompilationUnit cu) { 
     // does code generation work using Java Model 
    } 

} 
+0

錯誤日誌中是否有任何內容?另外,您是否可以在osgi控制檯中檢查插件的狀態 - 它處於什麼狀態? – katsharp 2012-08-14 20:30:04

+0

運行ss命令打印「427 \t啓動tg.companion_1.0.0.201208141117」。使用命令start 427激活插件,導致狀態爲ACTIVE。但是,沒有出現菜單貢獻。 – 01es 2012-08-15 04:26:23

+0

錯誤日誌中沒有錯誤 - 從Windows-> Show View打開。 – 01es 2012-08-15 06:00:15

回答

2

最後,問題已經解決了!

經過仔細審查項目結構後,發現build.properties文件(出於某種原因)沒有檢查plugin.xml。結果,plugin.xml沒有包含在導出嚮導jar文件生成的內容中。

將build.properties文件修改爲包含plugin.xml後,生成的jar文件將其包含並部署,沒有任何問題。

有趣的是,插件導出嚮導甚至沒有警告plugin.xml的排除,這是我個人預期的。

相關問題