1

我开发了一个简单的插件来生成一些例程代码。这个插件对包资源管理器的弹出菜单有贡献。从开发环境(来自 Eclipse RCP)运行时,它按预期工作Launch as Eclipse application——适当的菜单项出现在菜单中,并且它的调用符合预期。

但是,我很难将它部署到不同的 Eclipse 实例中。

开发的插件使用导出向导导出,生成一个单独的 jar 文件。这个 jar 文件已被放置到另一个 Eclipse 安装(新解包)的 dropings 目录中。当这个 Eclipse 实例启动时,Package Explorer 的弹出菜单不包含贡献的菜单项。来自 Eclipse Installation Details 的信息显示插件存在于 Plug-Ins 选项卡上,并且 Configuration 选项卡将其列为tg.companion (1.0.0.201208132302) "Companion Object Generator" [Starting].

我错过了什么?为什么贡献的菜单项不显示?

谢谢。


对于locationURI菜单贡献是popup:org.eclipse.jdt.ui.PackageExplorer,对于属性的价值allPopupstrue

该插件未签名。


这是可能会有所启发的插件文件。

插件.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> 

清单.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
    }

}
4

1 回答 1

2

终于,问题解决了!

在仔细检查项目结构后,发现 build.properties 文件(出于某种原因)没有检查 plugin.xml。结果,plugin.xml 未包含在导出向导生成的 jar 文件中。

修改 build.properties 文件以包含 plugin.xml 后,生成的 jar 文件将其包含并部署,没有任何问题。

有趣的是,插件导出向导甚至没有警告插件.xml 的排除,这是我个人所预料的。

于 2012-08-21T15:23:57.587 回答