Skip to content

Instantly share code, notes, and snippets.

@raquelbromao
Forked from rylan/EclipseJavaProjects.java
Created July 20, 2016 20:05
Show Gist options
  • Save raquelbromao/28def23c8c429ce40037d7919f0d1f74 to your computer and use it in GitHub Desktop.
Save raquelbromao/28def23c8c429ce40037d7919f0d1f74 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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment