This is what I use:
 
            /**
             * Import the Eclipse project at the given path.
             *
             * @param path
             *            The root directory containing the .project file.
             * @param flags
             *            {@link IResource#BACKGROUND_REFRESH} or 0.
             * @param monitor
             * @return The imported project.
             */
            public static IProject importProjectAt(String path, int flags,
                                    IProgressMonitor monitor) {
                        try {
                                    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
 
                                    IPath projectPath = new Path(path).append(".project");
                                    IProjectDescription description = workspace
                                                            .loadProjectDescription(projectPath);
 
                                    IProject project = workspace.getRoot().getProject(
                                                            description.getName());
 
                                    if (!project.exists()) {
                                                project.create(description,
 new SubProgressMonitor(monitor, 30));
                                    } else {
                                                monitor.worked(30);
                                    }
 
                                    project.open(flags, new SubProgressMonitor(monitor,
 70));
 
                                    return project;
 
                        } catch (CoreException e) {
                                    log(e);
                        }
 
                        return null;
            }
 
Jens.
 
 
Well, I'll change my question then. Is it possible to import a project to the current workspace programmatically,
 just like it is done by the "Import Existing Projects into Workspace" GUI option? I believe eclipse is just looking for .project files in the file tree we choose. I found a piece of code that should do it here -
http://blog.yahor.net/2009/05/import-existing-project-into-eclipse.html. Unfortunately it seems there is something more to it then this.
Best Regards,
Radosław Fijołek
W dniu 20 lipca 2011 14:52 użytkownik Andrew Gvozdev <angvoz.dev@xxxxxxxxx>
 napisał:
2011/7/20 Andrew Gvozdev <angvoz.dev@xxxxxxxxx>
Hi Radosław,
2011/7/20 Radosław Fijołek <lelokrates@xxxxxxxxx>
Hello!
Is it possible to programatically open/load a project using CDT? Unfortunately the following method:
String name = ...;
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
does not satisfy me, as I am not allowed to load the eclipse platform. I'd rather run my app from command line.
 
It is called "platform" for a reason. You cannot use CDT without eclipse platform including opening projects.
 
 
 
 
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev