During the coding of my Bulk Import Plugin, I had the needs to import java projects into a workspace via code. Via Eclipse’s API to be precise. After reading the code of what happens when you import a project, here is the critical bit of code:

Runnable runnable = new Runnable() {
    public void run() {
    try {
        IPath projectDotProjectFile = new Path(pathToMyProjectDir+ "/.project");
            IProjectDescription projectDescription =
                workspace.loadProjectDescription(projectDotProjectFile);
            IProject project = workspace.getRoot().
                getProject(projectDescription.getName());
            JavaCapabilityConfigurationPage.createProject(project, projectDescription
                .getLocationURI(), progressMonitor);
        }
        catch(CoreException e) {
            e.printStackTrace();
        }
    }
};

// and now get the workbench to do the work
final IWorkbench workbench = PlatformUI.getWorkbench();
workbench.getDisplay().syncExec(runnable);