List the projects in the eclipse workspace

If you are creating an eclipse plugin you might want to list the projects contained in the currently running workspace. This is very easy to do. Just checkout the coding below.

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
public IProject[] getProjects(){
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
return projects;

Some people does this the wrong way. They findout the path of the workspace and read the folder names in that workspace to determine the projects in the workspace. There can be several things that can go wrong here.

  1. The particular project may not be loaded in to the workspace even though its in the workspace path.
  2. The name of the project need not to be the same as the name of the folder which it resides in.
  3. There can be imported projects which are not copied to the workspace.

If you use the above method not only you can get the project in the workspace correctly you can control them also, like open/close/delete/refresh etc.


Tags: , , ,

3 Responses to “List the projects in the eclipse workspace”

  1. Akai Says:

    Thanks, this is really helpful

  2. Vikram Says:

    Note you also need to have “org.eclipse.core.resources” plug-in in your MANIFEST.MF dependencies

  3. Jens Driller (@jensdriller) Says:

    Thanks! Very simple and very helpful if you just started doing plugin development šŸ™‚

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: