如何在程序创建eclipse项目时检查项目是否存在

时间:2018-01-23 16:11:55

标签: eclipse rcp

通过下面的代码,我可以以编程方式创建eclipse项目,但我应该在创建之前检查项目是否存在,如果不存在,则应该创建它,否则,应该刷新它,任何提示都将受到欢迎!

    IProjectDescription description = null;
    IProject project = null;
    description = ResourcesPlugin.getWorkspace().loadProjectDescription(
            new Path(new File(projectfolder).getAbsolutePath()
                    + "/.project"));
    project = ResourcesPlugin.getWorkspace().getRoot()
            .getProject(description.getName());

    project.create(description, null);

    //project.refreshLocal(IResource.DEPTH_INFINITE, new  org.eclipse.core.runtime.NullProgressMonitor());

    project.open(null);

1 个答案:

答案 0 :(得分:2)

IProject扩展IResource,其方法为exists()

if (!project.exists()) {
    project.create(description, null);
}