stewchicken
stewchicken

Reputation: 531

How to checki if project exist or not when programmtically create eclipse project

by below code, I could create eclipse project programmatically, but I should check if project existing or not before creating it, if not existing, it should be created, otherwise, it should be refreshed, any hints will be more than welcome!

    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);

Upvotes: 0

Views: 84

Answers (1)

howlger
howlger

Reputation: 34135

IProject extends IResource which has the method exists():

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

Upvotes: 2

Related Questions