Skip to content

Instantly share code, notes, and snippets.

@rylan
Created February 14, 2012 21:05
Show Gist options
  • Save rylan/1830430 to your computer and use it in GitHub Desktop.
Save rylan/1830430 to your computer and use it in GitHub Desktop.
Get a list of all java projects open in an Eclipse workspace
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
public class EclipseJavaProjects {
public static List<IJavaProject> getJavaProjects() {
List<IJavaProject> projectList = new LinkedList<IJavaProject>();
try {
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IProject[] projects = workspaceRoot.getProjects();
for(int i = 0; i < projects.length; i++) {
IProject project = projects[i];
if(project.isOpen() && project.hasNature(JavaCore.NATURE_ID)) {
projectList.add(JavaCore.create(project));
}
}
}
catch(CoreException ce) {
ce.printStackTracce();
}
return projectList;
}
}
@meriembenchaaben
Copy link

hello, thanks for sharing, is this implemented as a plugin project?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment