Created
February 14, 2012 21:05
-
-
Save rylan/1830430 to your computer and use it in GitHub Desktop.
Get a list of all java projects open in an Eclipse workspace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
hello, thanks for sharing, is this implemented as a plugin project?