Eclipse 4 RCP插件:如何以编程方式将项目导入工作空间

问题描述 投票:0回答:1

我目前正在编写Eclipse 4 RCP插件,以使用CLI将项目导入Eclipse。我发现一些代码片段在启动Eclipse之前非常适合导入项目。但是,当我已经在运行Eclipse时尝试使用我的应用程序时,这些项目将无法正确导入。

这里是我到目前为止使用的代码:

IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProjectDescription description = workspace.loadProjectDescription(new Path(projectFile.toString()));
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
if (project.isOpen() == false) {  

    project.create(description, null);
    project.open(null)

    IOverwriteQuery overwriteQuery = new IOverwriteQuery() {
        public String queryOverwrite(String file) { 
        return ALL; }
    };

    String baseDir = projectFile.getParent();
    description.setLocation(new Path(projectFile.getAbsolutePath()));
    ImportOperation importOperation = new ImportOperation(project.getFullPath(),
        new File(baseDir), FileSystemStructureProvider.INSTANCE, overwriteQuery);
    importOperation.setCreateContainerStructure(false);

    try {
        importOperation.run(null);
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    project.refreshLocal(IProject.DEPTH_INFINITE, null);
    workspace.getRoot().refreshLocal(IProject.DEPTH_INFINITE, null);
    System.out.println("Importing project  " +description.getName());

因此,当我在Eclipse运行时执行我的应用程序时,所有项目都已创建并打开,但是它们未显示在Eclipse Package Explorer中,而当我退出Eclipse时,它们全部丢失了。

我在这里想念什么?

java eclipse plugins rcp
1个回答
0
投票

当您使用“以Eclipse应用程序身份运行”来运行程序时,Eclipse将使用separate测试工作区启动Eclipse的新实例。您的导入将导入到测试工作空间中。

“运行>运行配置”对话框将向您显示测试工作区的位置。

导入到主工作空间的唯一方法是将插件安装到主Eclipse。

请注意,Eclipse的两个实例不能安全地访问同一工作区,因为Eclipse并非设计为支持该工作区。 Eclipse通常无论如何都会拒绝这样做,但是如果您以某种方式进行管理,则可能会损坏工作区。

在单独的测试工作区中进行所有开发。如果确定插件正常运行,则可以将其安装在主Eclipse中。

© www.soinside.com 2019 - 2024. All rights reserved.