以编程方式启动Eclipse产品文件?

时间:2017-05-12 14:20:15

标签: eclipse-plugin eclipse-rcp

我想编写一个Eclipse插件,列出工作区中的所有产品文件,并能够启动它们。有没有办法以编程方式启动eclipse .product文件?

在Eclipse ide中的文件上有一个启动按钮。右键单击并选择以下内容即可启动该文件:"作为Eclipse Application运行。"

2 个答案:

答案 0 :(得分:0)

查看-application标志到eclipse命令行

见这里:https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fruntime-options.html

请注意,您还需要设置特定于平台的启动器

答案 1 :(得分:0)

代码可以在org.eclipse.pde.ui.launcher.EclipseLaunchShortcut中找到

我以这种方式使用代码:

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.pde.internal.core.iproduct.IProduct;
import org.eclipse.pde.internal.core.iproduct.IProductModel;
import org.eclipse.pde.internal.core.product.WorkspaceProductModel;
import org.eclipse.pde.internal.ui.PDEPlugin;
import org.eclipse.pde.internal.ui.launcher.LaunchAction;

@SuppressWarnings("restriction")
public class LaunchExecutor {

    private void launchProduct(IFile productFile) {
        String mode = "debug";
        IProductModel workspaceProductModel = new WorkspaceProductModel(productFile, false);
        try {
            workspaceProductModel.load();
        } catch (CoreException e) {
            PDEPlugin.log(e);
        }
        IProduct product = workspaceProductModel.getProduct();
        new LaunchAction(product, productFile.getFullPath().toOSString(), mode).run();
    }

}